Skip to content

Instantly share code, notes, and snippets.

@sathya-moneysmart
Last active November 22, 2017 04:29
Show Gist options
  • Save sathya-moneysmart/7305b13183556cf37ae9d33b850f065b to your computer and use it in GitHub Desktop.
Save sathya-moneysmart/7305b13183556cf37ae9d33b850f065b to your computer and use it in GitHub Desktop.
Capybara Setup for selenium with headless chrome
require 'capybara/rails'
require 'capybara/rspec'
require 'selenium/webdriver'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, args: ['--window-size=1280,1024'])
end
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu no-sandbox --window-size=1280,1024) }
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
end
Capybara.javascript_driver = :headless_chrome

Setup for Capybara selenium with headless chrome

This gist contains all you need to setup capybara for selenium with headless chrome.

  1. Add these gems to the Gemfile under test group
  gem 'capybara'
  gem 'chromedriver-helper
  gem 'selenium-webdriver'
  1. Copy the capybara.rb file into spec/support.

Make sure you have enabled this line in your rails_helper.rb

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

That's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment