Forked from mars/register_chrome_with_window_size.rb
Last active
September 8, 2019 05:14
-
-
Save khalilgharbaoui/abb358eec03831fc127feeee2eebd3a8 to your computer and use it in GitHub Desktop.
Set window size for Capybara/Selenium/chromedriver
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
# 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