Search code examples
javascriptcapybaracapybara-webkit

How to check if JavaScript alert is present (or not present) in a Capybara session?


I'm trying to write a test that confirms that no JavaScript alert is present on the page (because in capybara-webkit, it is silencing this alert, but in selenium it correctly raises an error). How can I write a test to expect(page).to_not have_alert?


Solution

  • This behavior will be changing in capybara-webkit 2.0 to follow the example set by Selenium.

    In the mean time, you can check page.driver.alert_messages to make sure no alerts have been opened.