View on GitHub

Tristan Hill

Blog about IT related stuff

PhantomJS with Ruby

I've just been experimenting with a couple of ways of using PhantomJS because of the speed benefits.

Option 1 is the poltergeist capybara driver, using with the phantomjs gem

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, :phantomjs => Phantomjs.path, phantomjs_options: ['--proxy=http://localhost:9889'])
end

The next one was a bit trickier to work out:

Selenium::WebDriver::PhantomJS.path = Phantomjs.path
Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser => :phantomjs)
end
Capybara.default_driver = :selenium

Both work well. I had a problem with javascript alert() and confirm() on both, as in verifying what the alert says. There are bugs open for these. There is also capybara webkit that I have not tried.