解決したいこと
現在Rspecでテストを書いているのですが、以下のようなエラーになってしまいます
Failure/Error: driven_by :selenium, using: :chrome, options: { desired_capabilities: caps } Webdrivers::BrowserNotFound: Failed to find Chrome binary.
https://gist.github.com/upinetree/fb71a947cc100e7918b7b280485d620c
https://obel.hatenablog.jp/entry/20210112/1610437485#f-4a625078
この方たちの記事を参考にさせていただいたところ、このエラーはwsl2側でchromeを使用したときに起こるようです。私はこれらの記事を参考に2番目の「 chromedriver-helper を利用しつつ、ChromeをWSL環境にインストールする」を実行し、wsl環境にchromeをインストールして再度テストを行いました。ですが、エラーは解決出来ませんでした。なので、現在方法1の「chromedriver-helper を使わずに、自分で chromedriver を設定する」を行っていますが、以下のようにエラーになってしまいます。
root@ffecfdb7f018:/app# bundle exec rspec spec/system 2022-03-25 06:06:13 WARN Selenium [DEPRECATION] [:driver_path] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead. An error occurred while loading spec_helper. Failure/Error: Selenium::WebDriver::Chrome.driver_path = "/mnt/c/Drivers/chromedriver_win32/chromedriver.exe" Selenium::WebDriver::Error::WebDriverError: not a file: "/mnt/c/Drivers/chromedriver_win32/chromedriver.exe" # /usr/local/bundle/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/platform.rb:141:in `assert_file' # /usr/local/bundle/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/platform.rb:145:in `assert_executable' # /usr/local/bundle/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/common/service.rb:54:in `driver_path=' # /usr/local/bundle/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/chrome.rb:35:in `driver_path=' # ./spec/spec_helper.rb:96:in `<top (required)>' No examples found. No examples found. Finished in 0.00013 seconds (files took 0.39168 seconds to load) 0 examples, 0 failures, 1 error occurred outside of examples Finished in 0.00013 seconds (files took 0.39168 seconds to load) 0 examples, 0 failures, 1 error occurred outside of examples
恐らく、エラーの内容からして、ファイルを見つけられないようです。なので私のPATHの設定が間違っていると思われます。
spec/spec_helper.rb
#実際に記述したもの require 'selenium-webdriver' Selenium::WebDriver::Chrome.driver_path = "/mnt/c/Drivers/chromedriver_win32/chromedriver.exe" # 参考にしたサイトのもの(windows側のファイルを読み込む) require 'selenium-webdriver' Selenium::WebDriver::Chrome.driver_path = "/mnt/c/Program Files/chromedriver_win32/chromedriver.exe" #参考にしたサイトのもの2(直接linux側に置いている?私はアクセス権限に引っかかってしまったので、 ダウンロードしたものをこのディレクトリに上手く移動させることができませんでした。 うまく移動出来ればエラーは解決できるかもしれません) Selenium::WebDriver::Chrome::Service.driver_path = '/usr/bin/chromedriver'
windows側にあるファイルのパスをそのままコピーしたもの
"C:\Drivers\chromedriver_win32\chromedriver.exe"
その他
・ruby3.0.3 rails 6.1.5 Dockerで環境構築を行いました。
・ファイルのパスの通し方が合っているか見て欲しいです。
・このエラーに対する解決策に対するアドバイスでもありがたいです。
・windows側でパスを通すのかlinux側でパスを通すのか分からなかったためどちらもパスを通しています。
root@ffecfdb7f018:/app# printenv HOSTNAME=ffecfdb7f018 RUBY_DOWNLOAD_SHA256=#一応伏せます RUBY_VERSION=3.0.3 PWD=/app BUNDLE_APP_CONFIG=/usr/local/bundle RUBY_MAJOR=3.0 HOME=/root LANG=C.UTF-8 BUNDLE_SILENCE_ROOT_WARNING=1 GEM_HOME=/usr/local/bundle TERM=xterm SHLVL=1 PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/mnt/c/Drivers/chromedriver_win32/ NODE_VERSION=15.0.1 _=/usr/bin/printenv
追記
どうやらパスは通っているようです
何が原因か分かりませんが、とりあえず最初のエラーからやり直しています
Webdrivers::BrowserNotFound: Failed to find Chrome binary.
何かしらアドバイスがあればよろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/03/25 10:21
2022/03/26 00:47