Replacing “Selenium” by “Poltergeist”


From the tip by my friend @pellegrino, I replaced “Selenium” with “Poltergeist” in a personal project. Poltergeist is a PhantomJS driver for Capybara.

Basically, this is what I did:

Include the following code to Gemfile:

gem 'poltergeist'

Update Capybara configuration:

Capybara.configure do |config|
  # config.javascript_driver = :selenium
  config.javascript_driver = :poltergeist

And 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 got this error:

undefined method `switch_to'

I tried to fix it and I find out that Poltergeist always returns true for a call to window.confirm. There’s no way to make it return false (at the moment), but it should not prevent your test from running.

So, I just removed that line and it works fine!


Finished in 1 minute 35.45 seconds

Finished in 41.03 seconds
  • jack

    very nice.
    Except…. which file is the capybara config supposed to go in?????

  • Lucas Caton


    The Capybara config is in spec/spec_helper.rb!