Skip to content

Instantly share code, notes, and snippets.

@zedtux
Created March 16, 2018 06:47
Show Gist options
  • Save zedtux/9420eb86a16ef8322494c6e960ff4d69 to your computer and use it in GitHub Desktop.
Save zedtux/9420eb86a16ef8322494c6e960ff4d69 to your computer and use it in GitHub Desktop.
Capybara configuration to be used with the SeleniumHQ/docker-selenium Docker image (https://github.com/SeleniumHQ/docker-selenium)
# Capybara defaults to CSS3 selectors rather than XPath.
# If you'd prefer to use XPath, just uncomment this line and adjust any
# selectors in your step definitions to use the XPath syntax.
# Capybara.default_selector = :xpath
Capybara.register_driver :chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: [
'--disable-default-apps',
'--disable-extensions',
'--disable-infobars',
'--disable-notifications',
'--disable-password-generation',
'--disable-password-manager-reauthentication',
'--disable-password-separated-signin-flow',
'--disable-popup-blocking',
'--disable-save-password-bubble',
'--disable-translate',
'--incognito',
'--mute-audio',
'--no-default-browser-check',
'--window-size=1280,1024',
# --auto-open-devtools-for-tabs,
# --ignore-certificate-errors
]
},
prefs: {
download: { prompt_for_download: false },
credentials_enable_service: false,
profile: {
password_manager_enabled: false,
default_content_settings: { popups: 0 },
content_settings: {
pattern_pairs: {
'*' => { 'multiple-automatic-downloads' => 1 }
}
}
}
}
)
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: "http://selenium:#{ENV['SELENIUM_PORT']}/wd/hub",
desired_capabilities: capabilities,
http_client: client
)
end
# Defines headless chrome as the Capybara JavaScript driver
Capybara.javascript_driver = :chrome
# Forces all tests to run in Javascript mode
Capybara.default_driver = Capybara.javascript_driver
Capybara.default_max_wait_time = 15
Capybara.server_host = '0.0.0.0' # bind to all interfaces
Capybara.always_include_port = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment