Browsed by
Month: June 2012

Replacing “Selenium” with “Poltergeist”

Replacing “Selenium” with “Poltergeist”


My friend @pellegrino give me an awesome tip: to replace “Selenium” with “Poltergeist”. For those who don’t know, Poltergeist is a PhantomJS driver for Capybara. I’ve done it in some projects and it works so well!

So, let’s do it:

Include the gem to your Gemfile:

gem 'poltergeist'

Update Capybara configuration:

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

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'

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

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

This is the improvement from the first project I’ve done it:

Finished in 1 minute 35.45 seconds

Finished in 41.03 seconds

Hope that can be useful for you!