Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver can't find Firefox when installed with Homebrew cask

Homebrew cask does some app linking magic on Mac OS X. Apparently it's not good enough because Selenium WebDriver looking for the Firefox executable can't find it. The following is an error message from an RSpec test run with Capybara driving Selenium.

What is a good way to hint the location of the Firefox executable?

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'
like image 715
Sim Avatar asked Jan 24 '15 20:01

Sim


2 Answers

As the error msg says: You have to specify Selenium::WebDriver::Firefox::Binary.path for custom app paths.

# in spec_helper.rb
require 'selenium/webdriver'

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

If you don't want to touch the test framework, you can install firefox to /Applications (default path selenium searches for) to make it work without setting the Binary.path.

brew cask install --appdir="/Applications" firefox
like image 111
Markus Avatar answered Sep 28 '22 09:09

Markus


I just added the code for Selenium to look for this directory specifically without needing to set it or change appdir. It will be available in the selenium-webdriver gem 2.49+

like image 43
titusfortner Avatar answered Sep 28 '22 09:09

titusfortner