Search code examples
ruby-on-railswebkitcapybara-webkitbootbox

Interacting with bootbox modals with Capybara-Webkit


Gem versions: Rails 4.1.14.rc2, Capybara 2.5.0, capybara-webkit 1.7.1

Our application is using bootbox modals to express soft validations for certain inputs. I am trying to use the accept_confirm with block method to capture the modal before Webkit automatically accepts it like so:

modal = accept_confirm do
  fill_in " Date of birth", with: "12/31/2015"
  click_on "Update Spouse"
end

expect(modal).to # have some sort of message

I receive this error in response:

 Failure/Error: modal = accept_confirm do
 Capybara::ModalNotFound:
   Timed out waiting for modal dialog

Does anybody have any experience using Webkit with bootbox modals?

***** UPDATE WITH SOLUTION *****

This was a race condition. Webkit moves faster than bootbox and it wasn't using capybara's wait time for some reason. Adding a sleep 0.5 after the event that triggers the bootbox modal allows the test to run properly. See example below:

fill_in " Date of birth", with: "12/31/2015"
click_on "Add benefit"
sleep 0.5

expect(page).to have_content "some warning message..."
click_on "Make Correction"

sleep 0.5
fill_in " Date of birth", with: "12/31/1905"
click_on "Add benefit"

sleep 0.5
expect(page).to have_content "some warning message..."
click_on "Make Correction"

Solution

  • The Capybara modal API is for interacting with system modals -- generated by calling window.alert/confirm/prompt in JS -- bootbox modals aren't system modals, they're just standard html elements. You interact with them like any other element on a page.