Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I correct this Selenium initialisation command deprecation warning?

Using Rails 6 I'm trying to set up selenium in headless mode for system tests, I'm using this statement in application_system_test_case.db:

driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]

(according to Agile Web Dev Rails 6 tutorial)

but it gives me this deprecation warning:

Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated. Use :capabilities with an Array of value capabilities/options if necessary instead.

I've done some searching in Selenium docs but I my basic code skills still leave me unclear as to how I should correct this. Can anyone advise how I can correct this?

(My amateur guesswork trials of things like:

driven_by :selenium, :capabilities['headless_chrome', 'screen_size: 1400, 1400']

all result in errors)

like image 314
jbk Avatar asked Jan 25 '23 05:01

jbk


1 Answers

summarized:

Capybara.register_driver :https_chrome do |app|
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--allow-insecure-localhost')
  options.add_argument('--ignore-certificate-errors')

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    capabilities: [options]
  )
end

Capybara.register_driver :headless_https_chrome do |app|
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument('--headless')
  options.add_argument('--allow-insecure-localhost')
  options.add_argument('--ignore-certificate-errors')

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    capabilities: [options]
  )
end
like image 108
Dorian Avatar answered Apr 08 '23 21:04

Dorian