Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save khalilgharbaoui/abb358eec03831fc127feeee2eebd3a8 to your computer and use it in GitHub Desktop.
Save khalilgharbaoui/abb358eec03831fc127feeee2eebd3a8 to your computer and use it in GitHub Desktop.
Set window size for Capybara/Selenium/chromedriver
# This works best in 2019 forward because its basically the code from the gem itself with some tweaks added:
# https://github.com/teamcapybara/capybara/blob/master/lib/capybara/registrations/drivers.rb
# The additional option/flags work for me but you probebly want to checkout what you would need here first:
# https://peter.sh/experiments/chromium-command-line-switches/
Capybara.register_driver :selenium_chrome_headless do |app|
# Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
opts.args << '--window-size=1920,1080'
opts.args << '--force-device-scale-factor=0.95'
opts.args << '--headless'
opts.args << '--disable-gpu'
opts.args << '--disable-site-isolation-trials'
opts.args << '--no-sandbox'
end
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.javascript_driver = :selenium_chrome_headless
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment