LoginSignup
3
4

More than 3 years have passed since last update.

Cloud9でRails 6.0のSeleniumとGoogle Chromeを使える設定しましょう!

Last updated at Posted at 2020-01-21

みなさん、お疲れ様です!

Cloud9で元気いっぱいで新しいRails6アプリを作ろうと思っている方、
必ずテストも作りたいよね!

もうグーグルクロームをインストールしていますよね? このバッシュスクリプトはめっちゃ便利です。

$ curl https://intoli.com/install-google-chrome.sh | bash

そしてSeleniumのシステムテストを稼働すると、このエラーはありますでしょうか?

$ rails test:system
Run options: --seed 47710
# Running:
E
Error:
WelcomeTest#test_visiting_the_index:
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    test/system/welcomes_test.rb:5:in `block in <class:WelcomeTest>'

気を落ち込まないように!

  • グーグルのバージョンを確認してください
$ google-chrome-stable -version
Google Chrome 79.0.3945.130 
  • 正しいchrome-webdriverをダウンロードして、インストールします。
    https://chromedriver.chromium.org/downloads
    で自分のバージョンをダウンロードしてください。例えば今の場合、79が必要ね
$ wget -N https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
$ unzip chromedriver_linux64.zip
$ sudo mv -f chromedriver /usr/local/bin/chromedriver
$ sudo chown root:root /usr/local/bin/chromedriver
$ sudo chmod 0755 /usr/local/bin/chromedriver
$ chromedriver --version
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) // OK!!!!!!
  • Railsのシステムテスト用のオプションを設定します
/test/application_system_test_case.rb
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, 
                       screen_size: [1400, 1400], 
                       options: { args: %w[headless disable-gpu] }
end

  • 確認!
$ rails test:system

Run options: --seed 49276

# Running:

2020-01-21 01:54:40 WARN Selenium [DEPRECATION] :args or :switches is deprecated. Use Selenium::WebDriver::Chrome::Options#add_argument instead.
Capybara starting Puma...
* Version 4.3.1 , codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:41043
.

Finished in 1.324751s, 0.7549 runs/s, 0.7549 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

まあ後でdeprecationsの問題に考えましょうね、
とりあえず稼働かどうか確認してください!

いかがでしたか?問題なかった?コメント、煽りはコメントに書いてください!

3
4
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
3
4