6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

はじめに

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

これで解決!!

6
6
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?