-
-
Save mars/6957187 to your computer and use it in GitHub Desktop.
Capybara.register_driver :chrome do |app| | |
Capybara::Selenium::Driver.new(app, | |
browser: :chrome, | |
desired_capabilities: { | |
"chromeOptions" => { | |
"args" => %w{ window-size=1024,768 } | |
} | |
} | |
) | |
end |
Worked like a charm, thanks :)
This didn't work for me, but this did:
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
args: ["--window-size=1024,768"]
)
end
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
args: ["--window-size=1024,768"]
)
end
worked for me
with selenium-webdriver 3.6.0 the following did the trick for me:
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument("--window-size=1024,768")
Capybara::Selenium::Driver.new(app,
browser: :chrome,
options: options
)
end
Thank you @rounders :)
@rounders' solution worked for me as well
desired_capabilities: {
"chromeOptions" => {
"args" => %w{ window-size=1024,768 }
}
}
This worked for me
capybara (>= 2.15)
chromedriver-helper (2.1.0)
Thanks @mars
I wanted headless and this is what I did:
Capybara.register_driver :selenium_chrome_headless do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless disable-gpu window-size=2500,2500) }
)
Capybara::Selenium::Driver.new app, browser: :chrome, desired_capabilities: capabilities
end
Capybara.javascript_driver = :selenium_chrome_headless
I wanted to drop it here, since all of these entries helped me understand what I might need to get to my setup.
This works best in 2019:
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
This is 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/
KG
Also found working solution in actionpack
def register_selenium(app)
Capybara::Selenium::Driver.new(app, **{ browser: @browser.type }.merge(browser_options)).tap do |driver|
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
end
end
2023 checking in here, here's what worked for me:
Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
%w[
incognito
disable-extensions
auto-open-devtools-for-tabs
window-size=1920,1080
].each { options.add_argument _1 }
%w[
headless
disable-gpu
].each { options.add_argument _1 } if %w[1 on true].include?(ENV['HEADLESS'])
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.default_driver = :selenium_chrome
Capybara.javascript_driver = :selenium_chrome
2023 checking in here, here's what worked for me:
Capybara.register_driver :selenium_chrome do |app| options = Selenium::WebDriver::Chrome::Options.new %w[ incognito disable-extensions auto-open-devtools-for-tabs window-size=1920,1080 ].each { options.add_argument _1 } %w[ headless disable-gpu ].each { options.add_argument _1 } if %w[1 on true].include?(ENV['HEADLESS']) Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.default_driver = :selenium_chrome Capybara.javascript_driver = :selenium_chrome
I was not able to get this to work for me with the HEADLESS=true bundle exec rspec
syntax. I ended up registering two drivers :selenium_chrome
and :selenium_chrome_headless
and using a separate selenium.rb
:
# spec/support/selenium.rb
RSpec.configure do |config|
config.before(:each) do
if ENV.fetch('HEADLESS', false)
driven_by :selenium_chrome_headless
else
driven_by :selenium_chrome
end
end
end
I had to do:
Capybara.register_driver :selenium do |app|
For this to work