ruby - 当我指定 "Mozilla geckodriver"时,为什么 capybara 要寻找 "chromedriver"?

标签 ruby selenium capybara

我有一个 Rspec 设置,其中包含 capybara 的规范支持文件,如下所示:

require 'capybara/rails'
require 'capybara/rspec'
require 'selenium-webdriver'

Capybara.configure do |config|
  config.always_include_port = true
  config.app_host = 'http://www.myteaspoon.pdev'
  config.default_max_wait_time = 5
end

Capybara.register_driver(:chrome_headless) do |app|
  options = Selenium::WebDriver::Chrome::Options.new(
    args: %w[headless disable-gpu no-sandbox]
  )

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

Capybara.default_driver = :chrome_headless

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

但是,当我尝试运行某些规范时,出现以下错误:

Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver. Please download the server from
https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH.
More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.
from /Users/nk/.rvm/gems/ruby-2.5.3@au/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:136:in `binary_path'

可能出了什么问题,我该如何调试?

我已经使用以下方法安装了 chromedriver:brew cask install chromedriver

它似乎在路径中:

$ chromedriver -v
ChromeDriver 76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809@{#1024})

最佳答案

当您需要 capybara/rspec 时,会安装一个 Hook ,将当前驱动程序设置为 Capybara.javascript_driver 的值,用于任何带有 :js 元数据的测试 - https://github.com/teamcapybara/capybara/blob/master/lib/capybara/rspec.rb#L23 -.如果您希望所有测试(有和没有 :js 元数据)都使用相同的驱动程序,那么您需要设置 Capybara.default_driver = Capybara.javascript_driver = :chrome_headless

关于ruby - 当我指定 "Mozilla geckodriver"时,为什么 capybara 要寻找 "chromedriver"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57608531/

相关文章:

ruby - 为什么 Ruby 不支持抽象类?

python - 如何在只读模式下设置输入的值

docker - 在 docker 容器中运行 cucumber 和 capybara

javascript - TypeScript 从另一个项目/模块导入类?

Java 相当于 Ruby 的 __FILE__?

ruby 类扩展

java - Selenium :moveByOffset() 不起作用

google-chrome - 为什么我必须点击两次才能使用 selenium 提交输入

javascript - 如何检查 Capybara session 中是否存在(或不存在)JavaScript 警报?

ruby-on-rails - 尝试访问表中的链接时无法让 Cucumber 脚本通过