Setting google chrome / chromedriver options correctly in version 75+ with selenium and capybara
Problem
Here's one that took me a surprising amount of digging to find an answer deep in a lone comment in a thread.
You're running your chrome/chromedriver-driven test suite and start getting mysterious errors, which might be related to problems that were previously solved by setting particular options. After some experimentation (hours of your life?) you discover that the chromedriver options are simply not being set anymore.
Solution
Starting with chromedriver 75, the name of the options key has changed. The old key name was chromeOptions
, the new key name is goog:chromeOptions
. To be honest I don't know which layers of selenium and chrome are involved in this change, but I know how to fix it. Illustrated here in the context of capybara:
Old
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w(
headless disable-gpu no-sandbox disable-dev-shm-usage window-size=1440,900
)
}
)
Capybara::Selenium::Driver.new app,
browser: :chrome, desired_capabilities: capabilities
end
New
Capybara.register_driver :headless_chrome do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
"goog:chromeOptions": {
args: %w(
headless disable-gpu no-sandbox disable-dev-shm-usage window-size=1440,900
)
}
)
Capybara::Selenium::Driver.new app,
browser: :chrome, desired_capabilities: capabilities
end