気ままに気ままのエンジニアブログ

定期的に得た知見を気ままに発信中

【Rspec/エラー】Unable to find Mozilla geckodriver.の解決方法

こんにちは。

最近間食が増えました。

どうもハチマキです。

はじめに

Rspecテスト時に発生したこのエラー。結構ググりましたが、なかなか解決できず苦戦しました。
今回はその解消方法について書いていこうと思います。

では早速行きましょう!

本日の概要 : Unable to find Mozilla geckodriver.の解決方法

事象

featureテストを実行した時に発生。。全然解決方法わからん。。

エラー例

$ bundle exec rspec spec/features/~~.rb 
Capybara starting Puma...
* Version 3.12.6 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:50950
F

Failures:

  1) ~~できること
     Failure/Error: visit root_path
     
     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.
     # ./spec/features/~~.rb :6:in `block (3 levels) in <top (required)>'

Finished in 0.40453 seconds (files took 3.64 seconds to load)
1 example, 1 failure

原因

エラー内容にも記載してあるように、「Mozillageckodriverが見つかりません。」だそうです。
解決方法を調べると、2つのやることが見えてきました!

  1. geckodriverをダウンロードする
  2. usr/binにgeckodriverファイルを移動

これを実行できれば、解決できそうやなぁ🤔

解決方法

geckodriverをインストールすれば解決できます。

$ brew install geckodriver
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/geckodriver-0.27.0.
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/c1ccd105a99db
#                                                                       ###                                                                     #######                                                                 ###########                                                             ##################                                                      ###########################                                             ###########################################                             ############################################################            ######################################################################## 100.0%
==> Pouring geckodriver-0.27.0.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/geckodriver/0.27.0: 6 files, 5.4MB

これで完了です!