在 Web 应用程序中,我使用 jQueryUI 模式对话框来确认操作:
function erase() {
$("#dialog").text("Are you sure want to delete this record?")
.attr("title", "Delete...")
.dialog({
modal: true,
buttons: {
Delete: function() {
$.ajax({
...snip...
success: function() {
self.location = "."; // returns to the welcome page
}
});
},
...snip...
}
});
}
该代码运行良好,但我无法成功使用 Capybara 对其进行测试:
...snip...
Capybara.default_driver = :webkit
...snip...
def in_dialog()
f = find('.ui-dialog')
end
feature 'Delete a record' do
...snip...
scenario 'for any record' do
click_on 'Delete...'
page.should have_content 'Are you sure want to delete this record?'
in_dialog.click_button 'Delete'
page.should have_content 'Welcome'
...snip...
end
end
Capybara 找到了按钮,但一切都好像从未触发过回调一样。
我尝试了不同的解决方法(我在 stackoverflow 上找到了其中几个):
- 睡觉,
- “等待ajax”,
- page.native.send_keys(:return) 而不是 click_button 'Delete',
- find('button', :text => 'Delete').click 而不是 click_button 'Delete',
- Selenium 驱动程序而不是 webkit 驱动程序。
没有工作。还有什么想法吗?