前提・実現したいこと
railsのRspecを使ってテストをしようとしたところ、
「chrome not reachable」と出てきてエラーとなってしまいました。
他サイトでも原因が記載されているので試してみたのですが、うまくいかず。。
解決方法ご存じの方いらっしゃいますでしょうか?
不足情報ございましたら、ご指摘ください。
■環境
windows10, ubuntu v18.04
■試したサイト
・https://qiita.com/eRy-sk/items/f71663242b01d57be85a
・http://www.stockdog.work/entry/2017/08/22/231718 ←プロセスは1つのみ。killできず。
■テスト結果
2019-08-01 10:35:03 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead. 2019-08-01 10:35:04 WARN Selenium [DEPRECATION] :args or :switches is deprecated. Use Selenium::WebDriver::Chrome::Options#add_argument 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:58568 FF Failures: 1) タスク管理機能 一覧表示機能 ユーザーAがログインしているとき ユーザーAが作成したタスクが表示される Got 0 failures and 3 other errors: 1.1) Failure/Error: expect(page).to have_content '最初のタスク' Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> # ./spec/system/tasks_spec.rb:20:in `block (4 levels) in <top (required)>' 1.2) Failure/Error: Unable to infer file and line number from backtrace Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> # ------------------ # --- Caused by: --- # Selenium::WebDriver::Error::WebDriverError: # chrome not reachable # (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> 1.3) Failure/Error: Unable to infer file and line number from backtrace Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> 2) タスク管理機能 一覧表示機能 ユーザーBがログインしているとき ユーザーAが作成したタスクが表示されない Got 0 failures and 3 other errors: 2.1) Failure/Error: visit login_path Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> # ./spec/system/tasks_spec.rb:10:in `block (3 levels) in <top (required)>' 2.2) Failure/Error: Unable to infer file and line number from backtrace Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> # ------------------ # --- Caused by: --- # Selenium::WebDriver::Error::WebDriverError: # chrome not reachable # (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> 2.3) Failure/Error: Unable to infer file and line number from backtrace Selenium::WebDriver::Error::WebDriverError: chrome not reachable (Session info: headless chrome=76.0.3809.87) # #0 0x7f8065e937a9 <unknown> Finished in 13.95 seconds (files took 3.16 seconds to load) 2 examples, 2 failures Failed examples: rspec ./spec/system/tasks_spec.rb:19 # タスク管理機能 一覧表示機能 ユーザーAがログインしているとき ユーザーAが作成したタスクが表示される rspec ./spec/system/tasks_spec.rb:27 # タスク管理機能 一覧表示機能 ユーザーBがログインしているとき ユーザーAが作成したタスクが表示されない
追記)
ご指摘ありがとうございます。
コメントアウトの部分も含めて一旦貼り付けます。
■テストで使用するgemとバージョン
group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 2.15' gem 'selenium-webdriver' #バージョン3.142.3 # Easy installation and use of chromedriver to run system tests with Chrome gem 'webdrivers' #バージョン4.1.2 end
■rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") end
■spec_helper.rb
require 'capybara/rspec' RSpec.configure do |config| config.before(:each, type: :system) do driven_by :selenium, using: :headless_chrome, screen_size: [1280, 800], options: { args: ["headless", "disable-gpu", "no-sandbox", "disable-dev-shm-usage"] } end # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. config.expect_with :rspec do |expectations| # This option will default to `true` in RSpec 4. It makes the `description` # and `failure_message` of custom matchers include text for helper methods # defined using `chain`, e.g.: # be_bigger_than(2).and_smaller_than(4).description # # => "be bigger than 2 and smaller than 4" # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| # Prevents you from mocking or stubbing a method that does not exist on # a real object. This is generally recommended, and will default to # `true` in RSpec 4. mocks.verify_partial_doubles = true end # This option will default to `:apply_to_host_groups` in RSpec 4 (and will # have no way to turn it off -- the option exists only for backwards # compatibility in RSpec 3). It causes shared context metadata to be # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin # This allows you to limit a spec run to individual examples or groups # you care about by tagging them with `:focus` metadata. When nothing # is tagged with `:focus`, all examples get run. RSpec also provides # aliases for `it`, `describe`, and `context` that include `:focus` # metadata: `fit`, `fdescribe` and `fcontext`, respectively. config.filter_run_when_matching :focus # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. config.example_status_persistence_file_path = "spec/examples.txt" # Limits the available syntax to the non-monkey patched syntax that is # recommended. For more details, see: # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode config.disable_monkey_patching! # Many RSpec users commonly either run the entire suite or an individual # file, and it's useful to allow more verbose output when running an # individual spec file. if config.files_to_run.one? # Use the documentation formatter for detailed output, # unless a formatter has already been configured # (e.g. via a command-line flag). config.default_formatter = "doc" end # Print the 10 slowest examples and example groups at the # end of the spec run, to help surface which specs are running # particularly slow. config.profile_examples = 10 # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = :random # Seed global randomization in this process using the `--seed` CLI option. # Setting this allows you to use `--seed` to deterministically reproduce # test failures related to randomization by passing the same `--seed` value # as the one that triggered the failure. Kernel.srand config.seed =end end
回答2件
あなたの回答
tips
プレビュー