0
0

More than 3 years have passed since last update.

RspecでCapybara js: true を入れるとCould not find Firefox binary (os=macosx)というエラーが出る

Last updated at Posted at 2020-11-07

エラー内容

Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=

Firefoxがダウンロードされていないよというエラーが出ます。

解決法

仮想環境でアプリケーションを作成してない人はMacOSだと

brew cask install --appdir="/Applications" firefox

でfireboxをダウンロードすればOKです。

ここからが自分が詰まったところ

自分の場合Vagrant環境でアプリケーション作成していたので上記のコードを実行しても
VagrantにはMacOSを使用して構築してないため
command not foundがでる。
それに気付くのに20分程かかりました😭
自分のVagrant環境はCentOSであった為CentOSのやり方でfireboxダウンロード
ダウンロードの仕方は下記参考
https://qiita.com/snow_rain000/items/551e35e76b92df06f7ea

エラー解決と思ったら

fireboxをダウンロードしてbundle exec rspecを実行すると

selenium::webdriver::error::unknownerror: process unexpectedly closed with status 1

というエラーが出ました。
エラー内容の原因としてはselenium::webdriverが正しく動いてないようでしたので

rails_helper
Capybara.register_driver :selenium do |app|
  options = Selenium::WebDriver::Chrome::Options.new

  options.add_argument('--no-sandbox')
  options.add_argument('--headless')
  options.add_argument('--disable-gpu')
  options.add_argument('--disable-dev-shm-usage')
  options.add_argument('--window-size=1680,1050')

  Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

をrails_helperに記載すると、テストが通りました!!!
他にもgem 'capybara' gem 'selenium-webdriver' gem 'webdrivers'を最新版にbundle updateして、chromeをダウンロードしたり色々やったので上記で失敗した場合は試してみてください。

最後に

一時間くらいかかりました😭
本当に解決できてよかったです。
他の人がエラー出た際にこの記事で解決できるように祈っています。

0
0
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
0
0