0
0

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.

【Rails】Chrome Headless モード on HerokuCI エラー集

Last updated at Posted at 2019-05-28

はじめに

HerokuCIに関する記事は他のCIに比べ少なく、依存ライブラリの変化などによりドキュメント通りに実装しても動かなくハマったところをまとめておきます。
本記事は、2019年5月時点での実装になっています。内容の更新により随時更新予定ではありますが、間違っている点・古くなっている点などあればお気軽にお知らせください。

エラー集

1. Session not created~~

エラー詳細

session not created: Chrome version must be between 70 and 73
  (Driver info: chromedriver=2.45.615355 (d5698f682d8b2742017df6c81e0bd8e6a3063189),platform=Mac OS X 10.14.4 x86_64)

このようなエラーが出る場合には、 chromedriver-helper をいまだに使用している可能性が高いです。 chromedriver-helperはサポートが終了しており、 webdrivers というGemに移行しましょう。

対処法

Gemfileを以下のように変更して bundle install しましょう。

Gemfile
# gem 'chromedriver-helper' # この行を削除
gem 'webdrivers' # この行を追加

2. DevTools listening on ws://~~ とでてCIが動かなくなる

エラー詳細

1. Session not created~~ のエラー解決の通り、 chromedriver-helper を削除し、HerokuCIを回すと、 DevTools listening on ws://127.0.0.1:9222/devtools/browser/ec46578f-304d-4a11-8441-fee4092aebac と表示された状態からCIが止まったような状況に遭遇することがあります。

解決方法

Webdrivers::Chromedriver のバージョンを指定してあげましょう。

spec/spec_helper.rb
require 'selenium-webdriver'
require 'capybara/rspec'
require 'webdrivers'
RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
  config.shared_context_metadata_behavior = :apply_to_host_groups
end

# この部分を指定
Webdrivers::Chromedriver.version = '2.46'

chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)

options = {}
options[:args] = ['headless', 'disable-gpu', 'window-size=1280,1024']
options[:binary] = chrome_bin if chrome_bin
Capybara.register_driver :headless_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    options: Selenium::WebDriver::Chrome::Options.new(options)
  )
end

Capybara.javascript_driver = :headless_chrome

詳しくは、こちらのIssueを参照してください。

参考

  1. Heroku CI: Browser and User Acceptance Testing (UAT)
  2. heroku-buildpack-google-chrome
  3. session not created: Chrome version must be between
  4. Migrating from chromedriver-helper (Heroku production) #72
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?