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
- https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities
- https://www.lambdatest.com/blog/desired-capabilities-in-selenium-testing/
- Selenium include firefox profile into DesiredCapabilities for Remote Driver
- https://www.selenium.dev/documentation/webdriver/remote_webdriver/
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
CodePudding user response:
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.
CodePudding user response:
# 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.