Quantcast
Viewing latest article 7
Browse Latest Browse All 66

Replacing "Selenium" with "Poltergeist"

Image may be NSFW.
Clik here to view.
Poltergeist

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.configuredo|config|# config.javascript_driver = :seleniumconfig.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:

undefinedmethod`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!


Viewing latest article 7
Browse Latest Browse All 66

Trending Articles