In a Web application, I use a jQueryUI modal dialog to confirm an action:
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...
}
});
}
The code works pretty well, but I couldn’t succeed in testing it with 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 finds the button but everything goes as if the callback were never fired.
I tried different workarounds (several of which I found on stackoverflow):
- sleep,
- “wait for ajax”,
- page.native.send_keys(:return) instead of click_button ‘Delete’,
- find(‘button’, :text => ‘Delete’).click instead of click_button ‘Delete’,
- Selenium driver instead of webkit driver.
None worked. Any other idea?
You posted code that you use to interact with the server in comments.
I followed those steps manually in browser but click on the button “Supprimer” returns 409 error and nothing else happens. That’s why nothing happens in your test when you click this button.