Cucumber, Capybara, Selenium, and Alerts
Although I try to avoid alert boxes in general, sometimes using them makes sense, especially when initially building out a feature.
This morning I was using Cucumber (and Capybara) to test deleting an object on a small project, and I needed to figure out how to click OK to dismiss in an alert and have the scenario continue. Here's the Cucumber step I ended up using:
When /^I click OK in the alert box$/ do
page.driver.browser.switch_to.alert.accept
endalert is returning an instance of Selenium::WebDriver::Alert, which also responds to dismiss and send_keys should you need to do something other than just click OK.