How to test a confirm dialog with Cucumber?

Yuval Karmi picture Yuval Karmi · Mar 16, 2010 · Viewed 35.5k times · Source

I am using Ruby on Rails with Cucumber and Capybara.

How would I go about testing a simple confirm command ("Are you sure?")?

Also, where could I find further documentation on this issue?

Answer

Derek Ekins picture Derek Ekins · Feb 15, 2011

The selenium driver now supports this

From Capybara you would access it like this:

page.driver.browser.switch_to.alert.accept

or

page.driver.browser.switch_to.alert.dismiss

or

 page.driver.browser.switch_to.alert.text