Migrating Your Capybara Driver from PhantomJS to Headless ChromeDriver
Newsflash: Vitaly Slobodin, the PhantomJS maintainer, is stepping down, since Google Chrome version 59 will ship with its own headless option. This means you’re going to have to move all your capybara tests from PhantomJS into ChromeDriver.
If you’re coming from poltergeist, which runs PhantomJS, you’lll have to install selenium-webdriver,
# Gemfile
group :test do
gem 'selenium-webdriver'
end
Then you’ll have to install the latest chromedriver
brew install chromedriver
Then register selenium-webdriver as your capybara driver, with chrome as the browser.
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu] }
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
end
Capybara.default_driver = :headless_chromium
For more chromeOptions
: check the headless chrome documentation.
disable-gpu
is temporarily required to run headless, but it may not be necessary in the future.