ruby-on-rails Rails 7 / Capybara with Selenium-Webdrivers失败(未知关键字::能力)

vltsax25  于 2023-10-21  发布在  Ruby
关注(0)|答案(2)|浏览(127)

我正在为我的rails rspec系统测试更新selenium / webdrivers。我曾经有webdriver gem,现在它告诉我我需要使用selenium-webdriver。我已经安装了该宝石,根据Gemfile.lock它的v4.12.0这应该是最新的.
然而,rspec/rails_helper.rb中的以下配置会产生如下错误:

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

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

有什么提示吗?我试着在“desired_capabilities”上做些手脚,但这并没有改变任何事情。

3qpi33ja

3qpi33ja1#

你使用的是什么版本的Rails?我也遇到了同样的问题,升级到Rails 7.0.5版本解决了这个问题。在旧的Rails版本中,Action Pack使用了“capabilites”关键字,这在selenium-webdriver版本4.12中被弃用。

igsr9ssn

igsr9ssn2#

selenium-webdriver gem在4.12.0版本中有changes,这会影响capabilities关键字:

4.12.0 (2023-08-31)
=========================
Ruby:
  * Fix bug preventing good error messages in Selenium Manager when stdout empty
  * Fix bug with Firefox not loading net/http library by default (#12506)
  * Remove support for using capabilities in local drivers

BiDi:
  * Released selenium-devtools 0.116.0 (supports CDP v85, v114, v115, v116)

之前

capabilities = Selenium::WebDriver::Chrome::Options.new(
  args: %w[--headless --no-sandbox --disable-gpu],
  binary: ENV.fetch('GOOGLE_CHROME_SHIM', nil),
)

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

之后

Capybara.register_driver :headless do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: capabilities # change keyword
  )
end

相关问题