指定“ chromedriver”后,水豚为什么要寻找“ Mozilla geckodriver”?

时间:2019-08-22 11:40:26

标签: ruby selenium capybara

我有一个带有水牛规格支持文件的Rspec设置,如下所示:

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'

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

我已使用brew cask install chromedriver

安装了chromedriver

而且似乎在路上:

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

1 个答案:

答案 0 :(得分:0)

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