My friend @pellegrino gave me an awesome tip: replace Selenium with Poltergeist. For those who don't know, Poltergeist is a PhantomJS driver for Capybara. I've done it in a few projects and it works very well!
NOTE: Poltergeist project has been discontinued in 2020.
In order to do it, include the gem to your Gemfile:
ruby
gem "poltergeist"
Update your Capybara configuration:
ruby
Capybara.configure do |config|
# config.javascript_driver = :selenium
config.javascript_driver = :poltergeistend
Run the specs!
If you are testing some confirm() JavaScript method and you have a code similar to page.driver.browser.switch_to.alert.accept, you'll get this error:
ruby
undefined method `switch_to`
While I was trying to fix it, I found out that Poltergeist always returns true from window.confirm.
There's no way (at the moment) to make it return false, but at least it won't prevent your test from passing: all I had to do was to remove that particular line and it solved the issue.
This is the results from the first project I've migrated: