Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sathiyaseelan/af1df9a7e700e3a481a8c34fe022a9ca to your computer and use it in GitHub Desktop.
Save sathiyaseelan/af1df9a7e700e3a481a8c34fe022a9ca 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