有沒有人能夠獲得jQuery UI對話框按鈕來響應click_button或selenium.click?我似乎無法得到這個工作。jQuery UI對話框按鈕不響應Selenium/Webrat中的click_button或selenium點擊
基本上,我試圖在使用Cucumber/Webrat/Selenium的Rails應用程序中的jQuery UI對話框中測試表單。
我有一個包含許多表格行的頁面,每一行點擊都會觸發一個帶有窗體的對話框。每個表單元素都有一個唯一的ID,所以標記是有效的。
由於按鈕可以通過對話框插件動態創建,我初始化對話框添加一個'保存'和'取消'按鈕。有趣的是,插件插入一個按鈕標籤,而不是輸入標籤。我也在open上添加了id,如下所示,所以按鈕可以被測試框架作爲目標。
$('.inventory_dialog').dialog({
autoOpen: false,
modal: true,
buttons: {
'Save': function() {
// ajax submit stuff
},
Cancel: function() {
// cancel stuff
}
},
open: function() {
// add ids to buttons for selenium
var inventory_id = $(this).attr('id').split('_').pop();
$('.ui-dialog-buttonpane')
.find('button:contains("Save")').attr('id', 'inventory_'+inventory_id+'_save_button')
.end()
.find('button:contains("Cancel")').attr('id', 'inventory_'+inventory_id+'_cancel_button');
}
});
的標記看起來像:
<div id="inventory_dialog_392827" class="inventory_dialog">
<form action="/suppliers/22/listings/27738/inventory/392827" class="edit_inventory" id="edit_inventory_392827" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div>
<div class="input_block">
<label for="inventory_392827_new_quantity">Quantity</label>
<input id="inventory_392827_new_quantity" name="inventory[new_quantity]" type="text" value="10" />
</div>
<div class="input_block">
<label for="inventory_392827_claim_quantities">Groups of</label>
<input id="inventory_392827_claim_quantities" name="inventory[claim_quantities]" type="text" value="6-8" />
</div>
</form>
</div>
我的黃瓜步驟(目前)是這樣的:
When /^I click the "(.+)" button in the inventory dialog$/ do |button_name|
debugger
selenium.click "//button[@id='inventory_#{@current_offer.id}_#{button_name.downcase}_button']"
selenium_wait
end
當我運行黃瓜和它打 '調試',我能在輸入字段中手動'selenium.click'。
selenium.click "//input[@id='inventory_392827_new_quantity']"
這成功地將光標置於該字段中。但是,單擊按鈕不起作用:
selenium.click "//button[@id='inventory_392827_save_button']"
當我鍵入的命令行調試,它返回零(我認爲是成功的,因爲沒有例外),但Firefox不會做任何事情。該對話框在瀏覽器中保持打開狀態。當我輸出response.body時,該按鈕存在。
我也試過
click_button "inventory_392827_save_button"
但「selenium_wait」命令超時,這意味着它不會看到該元素。
我卡住了...
您的標記不顯示的按鈕。按鈕是否已正確創建? – AutomatedTester 2009-12-07 09:39:42
這些按鈕是由jQuery對話框插件動態創建的,所以我沒有將它包含在原始標記中。 – cotopaxi 2009-12-08 02:18:04