Skip to content

Commit

Permalink
update register_driver to
Browse files Browse the repository at this point in the history
- use new Capybara::Selenium::Driver options
- allow firefox and firefox headless as well
- default to firefox_headless
  • Loading branch information
mathieujobin committed Mar 16, 2021
1 parent 368fb10 commit 805523c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
end

config.before(:each, browser: true) do
Capybara.current_driver = Capybara.javascript_driver = ENV.fetch("CAPYBARA_DRIVER", "chrome_headless").to_sym
Capybara.current_driver = Capybara.javascript_driver = ENV.fetch("CAPYBARA_DRIVER", "firefox_headless").to_sym
end
end
32 changes: 25 additions & 7 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
require "webdrivers"

def register_driver(name, args = [], opts = {})
def register_driver(browser, name, args, headless: false)
case browser
when :firefox
options = Selenium::WebDriver::Firefox::Options.new
when :chrome
options = Selenium::WebDriver::Chrome::Options.new
else
raise "what browser?"
end

Capybara.register_driver(name) do |app|
options = { args: args + ["window-size=1440,1080"] }
options[:binary] = ENV.fetch("GOOGLE_CHROME_SHIM", nil)
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: options.compact)
Capybara::Selenium::Driver.new(app, { browser: :chrome, desired_capabilities: capabilities }.merge(opts))
args.each { |arg| options.add_argument arg }
options.headless! if headless
Capybara::Selenium::Driver.new(app, browser: browser, options: options)
end
end

register_driver(:chrome)
register_driver(:chrome_headless, %w[headless disable-gpu no-sandbox disable-dev-shm-usage])
driver_arguments = %w[
disable-impl-side-painting
window-size=1440,1080
no-sandbox
disable-gpu
disable-dev-shm-usage
verbose
]
register_driver(:chrome, :chrome, driver_arguments)
register_driver(:chrome, :chrome_headless, driver_arguments, headless: true)
register_driver(:firefox, :firefox, driver_arguments)
register_driver(:firefox, :firefox_headless, driver_arguments, headless: true)

0 comments on commit 805523c

Please sign in to comment.