Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Headless Chrome within RSpec & Capybara
# spec/support/capybara_chrome.rb
require 'selenium/webdriver'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
RSpec.configure do
Capybara.server = :puma
Capybara.server_port = 5000
Capybara.register_driver(:chrome) do |app|
chrome_args = %w[window-size=1600,768]
chrome_args += %w[headless disable-gpu] unless ENV['TEST_CARTOON']
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: chrome_args }
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
end
Capybara::Screenshot.register_driver(:chrome) do |driver, path|
driver.browser.save_screenshot(path)
end
Capybara.javascript_driver = :chrome
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.