Ir para conteúdo principal

Replacing "Selenium" with "Poltergeist"

Lucas Caton

Lucas Caton



My friend @pellegrino gave 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 very well!

In order to do it, include the gem to your Gemfile:

gem 'poltergeist'

Update your 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 get this error:

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:

  • Before: Finished in 1 minute 35.45 seconds
  • After: Finished in 41.03 seconds

Hope you find it helpful as I did!

Post atualizado em 10/2/2017, 10:00:00 AM