Skip to content

Instantly share code, notes, and snippets.

@ruyrocha
Last active October 28, 2018 01:46
Show Gist options
  • Save ruyrocha/4cde4bb454b61e941790071cf696a180 to your computer and use it in GitHub Desktop.
Save ruyrocha/4cde4bb454b61e941790071cf696a180 to your computer and use it in GitHub Desktop.
Capybara with headless Chrome
Capybara.register_driver :chrome do |app|
# Ensure a reasonable amount of time for Read/Open timeouts
http_client = Selenium::WebDriver::Remote::Http::Default.new(
read_timeout: 30,
open_timeout: 30
)
# Explicitly set the Chrome capabilities
browser_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'args' => [
'headless',
'no-sandbox',
'disable-gpu',
'window-size=1920,1080',
'disable-setuid-sandbox'
]
}
)
Capybara::Selenium::Driver.new(
app,
http_client: http_client,
browser: :chrome,
desired_capabilities: browser_capabilities
)
end
Capybara.javascript_driver = :chrome
Capybara.default_max_wait_time = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment