Created
August 29, 2017 11:12
-
-
Save stokarenko/38a93a09a0958dc813686127b039bd4b to your computer and use it in GitHub Desktop.
Headless Chrome within RSpec & Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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