At work we do a lot of headless integration testing of our Rails applications, and we've been using PhantomJS & Capybara.
Here is what I had to do in my Rails application to switch over to headless chrome:
Added these two gems to my
test section of my rails
gem 'selenium-webdriver' gem 'chromedriver-helper'
Removed all code mentioning
Poltergeist in my
I'm using system specs now rather then feature specs, so I added these two sections to my
rails_helper. It's pretty handy to be able to run the specs in non-headless mode when developing.
config.before(:each, type: :system, js: true) do if ENV['HEADLESS'] driven_by :selenium_chrome_headless else driven_by :selenium end end Capybara.register_driver :selenium do |app| options = Selenium::WebDriver::Chrome::Options.new(args: ['disable-gpu']) Capybara::Selenium::Driver.new( app, browser: :chrome, options: options ) end
And here is what I needed to do to get chromium and the driver running locally on my computer
# Update the local chromedriver $ chromedriver-update # Install chromium so that chromedriver has something to drive! $ sudo apt install chromium-browser # And finally to test if its working $ chromedriver -> Starting ChromeDriver 70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778) on port 9515 -> Only local connections are allowed.