4

Super beginner here. Trying to update this test with Selenium WebDriver using Ruby the course I was going through uses the below which is deprecated.

driver = Selenium::WebDriver.for :remote, desired_capabilities: :firefox

The error I'm getting in cmd when I try to run the tests is

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

So I've tried to find examples of how to suppress the error mentioned in This Link, but I'm having trouble finding examples of how to implement that.

I've also tried to look up several ways to just use capabilities: as suggested, but I'm having trouble finding resources for that also, so I've just messed around and tried different combinations to no avail.

Curious if anyone knows of anything that would help me find the answer for this?

Also looked at these sources

Based off the last link, I believe the below should work? But I'm sure I'm just missing something with syntax.

driver = Selenium::WebDriver.for :Remote::Capabilities.firefox

Rajagopalan
  • 5,465
  • 2
  • 11
  • 29
BananaSheep
  • 41
  • 1
  • 3

2 Answers2

1

Selenium capabilities are not where they should be in Ruby. You want to avoid using Capabilities entirely now.

Here's an example in the Selenium documentation with a before/after for how to use Options properly: https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/#before

It does not match how the other Selenium languages do things, so I'm planning to change the deprecations in Selenium 4.3 to get them to match.

titusfortner
  • 4,099
  • 2
  • 15
  • 29
  • I think you have activated the notification for ruby and selenium-webdriver. But most of the questions are coming under ruby and selenium. – Rajagopalan May 10 '22 at 17:43
-1
# spec/rails_helper.rb

Capybara.server = :puma, { Silent: true }
Capybara.server_port = 9887
Capybara.register_driver :headless_chrome do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
    opts.args << '--headless'
    opts.args << '--disable-site-isolation-trials'
    opts.args << '--no-sandbox'
  end

  options.add_preference(:download, prompt_for_download: false, default_directory: Rails.root.join('tmp/capybara/downloads'))
  options.add_preference(:browser, set_download_behavior: { behavior: 'allow' })

  service_options = ::Selenium::WebDriver::Service.chrome(
    args: {
      port: 9515,
      read_timeout: 120
    }
  )

  remote_caps = Selenium::WebDriver::Remote::Capabilities.chrome(
    'goog:loggingPrefs': {
      browser: ENV['JS_LOG'].to_s == 'true' ? 'ALL' : nil
    }.compact
  )

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    capabilities: [remote_caps, options],
    service: service_options,
    timeout: 120
  )
end

Capybara::Screenshot.register_driver(:headless_chrome) do |driver, path|
  driver.browser.save_screenshot(path)
end

Capybara.javascript_driver = :headless_chrome

I'd hope this be helpfull for you.

Sergio Belevskij
  • 2,478
  • 25
  • 24
  • Fwiw, capybara does not get initialized the same way as selenium, which might be confusing to a beginner without context. – titusfortner May 10 '22 at 23:36