有没有人能够让 jQuery UI 对话框按钮响应 click_button 或 selenium.click?我似乎无法让它工作。
基本上,我正在尝试使用 Cucumber/Webrat/Selenium 在 Rails 应用程序中的 jQuery UI 对话框中测试表单。
我有一个包含许多表格行的页面,点击时每一行都会触发一个带有表单的对话框。每个表单元素都有一个唯一的 id,因此标记是有效的。
由于按钮可以由对话框插件动态创建,因此我初始化对话框以添加“保存”和“取消”按钮。有趣的是,插件插入了一个按钮标签,而不是一个输入标签。我还在打开时添加了 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
当我运行 Cucumber 并点击“调试器”时,我可以在输入字段中手动“selenium.click”。
selenium.click "//input[@id='inventory_392827_new_quantity']"
这成功地将光标放在该字段中。但是,单击按钮不起作用:
selenium.click "//button[@id='inventory_392827_save_button']"
当我在命令行调试器中键入它时,它返回 nil(我相信这是成功的,因为没有例外),但 Firefox 什么也不做。该对话框在浏览器中保持打开状态。当我输出 response.body 时,该按钮存在。
我也试过
click_button "inventory_392827_save_button"
但是“selenium_wait”命令超时,这意味着它看不到该元素。
我被困住了...