Help us understand the problem. What is going on with this article?

仮想環境に「Google Chrome」をインストールして、Railsのテスト実行時のエラーを解決

はじめに

Ruby on Railsの書籍【現場で使える Ruby on Rails 5速習実践ガイド】でテスト環境を構築中に下記のようなエラーが発生

$ bundle exec rspec spec/system/tasks_spec.rb

2019-06-03 17:21:24 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
Capybara starting Puma...
* Version 3.12.1 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:33289
F

Failures:

  1) タスク管理機能 一覧表示機能 ユーザーAがログインしているとき ユーザーAが作成したタスクが表示される
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: visit login_path

          Selenium::WebDriver::Error::WebDriverError:
            unable to connect to chromedriver 127.0.0.1:9515



          # ./spec/system/tasks_spec.rb:15:in `block (4 levels) in <top (required)>'

     1.2) Failure/Error: raise Error::WebDriverError, cannot_connect_error_text

          Selenium::WebDriver::Error::WebDriverError:
            unable to connect to chromedriver 127.0.0.1:9515


        ...(省略)...


Finished in 40.99 seconds (files took 1.56 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/system/tasks_spec.rb:21 # タスク管理機能 一覧表示機能 ユーザーAがログインしているとき ユーザーAが作成したタスクが表示される

環境

Vagrantで仮想環境を構築
Ubuntu VERSION="18.04.1 LTS (Bionic Beaver)"

Rails (5.2.1)
Ruby (2.5.1)
Selenium-webdriver (3.141)
capybara (3.12.0)
rspec-rails (3.8.1)
chromedriver-helper (2.1.0)

原因

仮想環境下にGoogle Chromeがインストールされていなかったので、chromedriver-helperがうまく動いてくれなかった。

仮想マシンにGoogle Chromeを追加する

1. Google Chromeのリポジトリを追加

$ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

2. ダウンロード

$ sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -

3. パッケージリストをアップデートし、chromeをインストール

$ sudo apt update && sudo apt install google-chrome-stable

4. 再度実行

$ bundle exec rspec spec/system/tasks_spec.rb

2019-06-03 17:55:54 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
Capybara starting Puma...
* Version 3.12.1 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:37449
...

Finished in 2.97 seconds (files took 2.23 seconds to load)
2 examples, 0 failures

これで解決!!

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away