ruby-on-railsselenium-webdrivercapybara

Rails 7 / Capybara with Selenium-Webdrivers fails (unknown keyword: :capabilities)


I am struggling with updating selenium / webdrivers for my rails rspec system tests. I used to have the webdriver gem, now it's telling me I need to use selenium-webdriver. I have installed that gem, according to Gemfile.lock it's v 4.12.0 which should be the latest.

The below configuration in rspec/rails_helper.rb however yields an error as follows:

Failure/Error:
            def create_bridge(caps:, url:, http_client: nil)
              Remote::Bridge.new(http_client: http_client, url: url).tap do |bridge|
                bridge.create_session(caps)
              end
            end
          
          ArgumentError:
            unknown keyword: :capabilities

Configuration in rails_helper.rb:

  Capybara.register_driver :chrome do |app|
    Capybara::Selenium::Driver.new(app, browser: :chrome)
  end

  Capybara.register_driver :headless_chrome do |app|
    options = Selenium::WebDriver::Remote::Options.chrome(
      'goog:chromeOptions': { args: %w(window-size=1400,1400) }
    )
    Capybara::Selenium::Driver.new app, browser: :chrome, options:
  end

Any hints? I tried messing around with "desired_capabilities" but that didn't change anything.


Solution

  • What version of Rails are you using? I had the same problem and upgrading to Rails version 7.0.5 fixed it. In older Rails versions Action Pack used "capabilites" keyword that is deprecated in selenium-webdriver version 4.12.