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
カピバラはボタンを見つけますが、コールバックが起動されなかったかのようにすべてが進みます。
さまざまな回避策を試しました(そのうちのいくつかはstackoverflowで見つけました):
- 寝る、
- "ajax を待つ",
- page.native.send_keys(:return) click_button '削除' の代わりに、
- find('button', :text => 'Delete').click 代わりに click_button 'Delete',
- Webkit ドライバーの代わりに Selenium ドライバー。
どれも機能しませんでした。他のアイデアはありますか?