12

Homebrewcask 在 Mac OS X 上做了一些应用程序链接魔术。显然它还不够好,因为 Selenium WebDriver 正在寻找 Firefox 可执行文件找不到它。以下是来自驱动 Selenium的RSpec测试运行的错误消息。Capybara

提示 Firefox 可执行文件位置的好方法是什么?

Failure/Error: Unable to find matching line from backtrace
 Selenium::WebDriver::Error::WebDriverError:
   Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:35:in `block in launch'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver.rb:67:in `for'
 # /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara/selenium/driver.rb:13:in `browser'
4

2 回答 2

22

正如错误消息所说:您必须指定Selenium::WebDriver::Firefox::Binary.path自定义应用程序路径。

# in spec_helper.rb
require 'selenium/webdriver'

Selenium::WebDriver::Firefox::Binary.path =
  "/opt/homebrew-cask/Caskroom/Firefox/latest/Firefox.app/Contents/MacOS/firefox"

如果您不想接触测试框架,可以将 firefox 安装到/Applications(selenium 搜索的默认路径)以使其工作而无需设置Binary.path.

brew cask install --appdir="/Applications" firefox
于 2015-01-25T00:02:52.313 回答
3

我只是添加了 Selenium 的代码来专门寻找这个目录,而不需要设置它或更改 appdir。它将在 selenium-webdriver gem 2.49+ 中可用

于 2016-01-08T16:52:27.357 回答