Last active
December 18, 2023 11:36
-
-
Save vhorb/dec95ecaf6f4899236a610f0d0a0dba9 to your computer and use it in GitHub Desktop.
Capybara register new driver for test
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
# Typically this faile named capybara.rb and needed for browser configuration. | |
# This file related to capybara 3.22.0 and webdriver 3.8.0 | |
require 'capybara/rspec' | |
require 'capybara-screenshot/rspec' | |
require 'webdrivers' | |
Capybara.register_driver :context_selenium_chrome do |app| | |
chrome_args = %w[window-size=1920,1080] | |
# for headless can be used config file or ENV variable. | |
chrome_args += %w[headless disable-gpu] if APP_CONFIG.dig('headless') | |
# after gem updates chromeOptions changed to 'goog:chromeOptions' - https://github.com/elgalu/docker-selenium/issues/201 | |
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( | |
'goog:chromeOptions': { args: chrome_args } | |
) | |
Capybara::Selenium::Driver.new app, | |
browser: :chrome, | |
desired_capabilities: capabilities | |
end | |
Capybara::Screenshot.register_driver(:context_selenium_chrome) do |driver, path| | |
driver.browser.save_screenshot(path) | |
end | |
# Available drivers: :rack_test, :selenium, :selenium_chrome, :selenium_chrome_headless, :chrome | |
Capybara.default_driver = :context_selenium_chrome | |
Capybara.javascript_driver = :context_selenium_chrome | |
# option to hide puma start logs | |
Capybara.server = :puma, { Silent: true } |
If you happened to encounter SeleniumHQ/selenium#2228 this will also auto open devtools for you in Chrome.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2023 checking in here, here's what worked for me: