LoginSignup
16
15

More than 5 years have passed since last update.

Homebrew caskでインストールしたFirefoxでSeleniumのセッションが作れない?

Posted at

FirefoxはSelenium2のドライバがデフォルトで同梱されているので、Google ChromeやIEのように別途ドライバをダウンロードしてくる必要がない。なので、Selenium Server Standaloneの起動は、-browser オプションを指定するだけですぐに使えるようになる。

$ java -jar selenium-server-standalone-2.42.2.jar -browser browserName=firefox,version=30,platform=MAC,maxInstances=2

しかし、Homebrew CaskでFirefoxをインストールした環境では、このコマンドではSeleniumのセッションを作ろうとすると、Firefoxのバイナリが見つからないという例外が発生してしまう。

例外の抜粋:

java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'suin.local', ip: '10.0.1.14', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_60'
Driver info: driver.version: unknown

...


Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'suin.local', ip: '10.0.1.14', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_60'
Driver info: driver.version: unknown

...

Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: MAC
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'suin.local', ip: '10.0.1.14', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_60'
Driver info: driver.version: FirefoxDriver

...

18:34:36.319 WARN - Exception: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: MAC
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'suin.local', ip: '10.0.1.14', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_60'
Driver info: driver.version: FirefoxDriver

SeleniumはFirefoxのバイナリが /Applications/Firefox.app/Contents/MacOS/firefox-bin があれば勝手にそれをロードしてくれるが、ない場合は明示的にバイナリのパスを指定する必要がある。Homebrew CaskでインストールするとFirefoxは /opt/homebrew-cask/Caskroom/ にインストールされ、~/Applcation にシンボリックリンクが張られる。このFirefoxをSeleniumから使うためには、 -Dwebdriver.firefox.bin パラメータでFirefoxのバイナリのパスを明示的に指定する。

$ java -jar selenium-server-standalone-2.42.2.jar -browser browserName=firefox,version=30,platform=MAC,maxInstances=2 -Dwebdriver.firefox.bin=$HOME/Applications/Firefox.app/Contents/MacOS/firefox-bin
16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15