web-dev-qa-db-ja.com

Selenium WebDriverエラー:無効なセッションID

私はアプリで機能テストを行うためにSelenium WebDriverとChromeを使用しています。すでに複数のRailsアプリをrspec、capybara、Seleniumでセットアップしていますが、これが機能しない理由はわかりません。

ここに問題があります。初めて機能テストを実行すると、計画どおりに機能します。ただし、2回目に実行すると、Seleniumが次のメッセージでクラッシュします。

Selenium :: WebDriver :: Error :: NoSuchDriverError:無効なセッションID(ドライバー情報:chromedriver = 74.0.3729.6(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729 @ {#29})、platform = Mac OS X 10.14.3 x86_64)

機能テストは他のアプリでも完全に機能するので、これはChromeとChromedriverの互換性の問題ではありません。

私は何日もこれに取り組んできましたが、何が起こっているのか理解できません

これが私の設定です:

  • Selenium-webdriver(3.141.0)
  • カピバラ(2.7.1)
  • Chrome 74およびchromedriver 74.0.3729.6

support/capyabara.rb

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w(headless disable-gpu) }
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome
Capybara.default_max_wait_time = 15

Rails_helper.rb

# frozen_string_literal: true

# This file is copied to spec/ when you run 'Rails generate rspec:install'
require File.expand_path("../../config/environment", __FILE__)

require "spec_helper"
require "rspec/Rails"
require 'capybara/Rails'
require 'capybara/rspec'
require 'Selenium-webdriver'
# https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-(and-RSpec)
require "devise"

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

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 = false

  config.include Devise::TestHelpers, type: :controller

  config.infer_spec_type_from_file_location!

  # Only retry when Selenium raises Net::ReadTimeout
  config.exceptions_to_retry = [Net::ReadTimeout]
end

support/database_cleander.rb

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.clean_with :truncation

    # Seed database
    load "#{Rails.root}/db/seeds.rb"
  end

  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each, type: :feature) do
    driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test

    if !driver_shares_db_connection_with_specs
      DatabaseCleaner.strategy = :truncation
    end
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.append_after(:each) do
    DatabaseCleaner.clean
  end
end

スタックトレース:

# ./spec/features/test_spec.rb:8:in `block (2 levels) in <top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/response.rb:69:in `assert_ok'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/response.rb:32:in `initialize'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/http/common.rb:84:in `new'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/http/common.rb:84:in `create_response'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/http/default.rb:104:in `request'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/http/common.rb:62:in `call'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/bridge.rb:166:in `execute'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/oss/bridge.rb:584:in `execute'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/remote/oss/bridge.rb:299:in `delete_all_cookies'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/Selenium-webdriver-3.141.0/lib/Selenium/webdriver/common/options.rb:81:in `delete_all_cookies'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara/Selenium/driver.rb:102:in `reset!'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara/session.rb:109:in `reset!'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara.rb:331:in `block in reset_sessions!'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara.rb:331:in `reverse_each'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara.rb:331:in `reset_sessions!'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara/rspec.rb:21:in `block (2 levels) in <top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:357:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:507:in `block in run_owned_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:506:in `each'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:506:in `run_owned_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:593:in `block in run_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:592:in `each'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:592:in `run_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:463:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:507:in `run_after_example'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:273:in `block in run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-Rails-3.6.0/lib/rspec/Rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:123:in `block in run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `loop'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:37:in `block (2 levels) in setup'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:251:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `map'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `run_examples'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:589:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `map'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1894:in `with_suite_hooks'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:113:in `block in run_specs'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/reporter.rb:79:in `report'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:112:in `run_specs'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:87:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/rspec-core-3.6.0/exe/rspec:4:in `<top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/bin/rspec:22:in `load'
# /Users/vincentrolea/.rbenv/versions/2.3.7/bin/rspec:22:in `<top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
# /Users/vincentrolea/.rbenv/versions/2.3.7/lib/Ruby/gems/2.3.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
# /Users/vincentrolea/.rbenv/versions/2.3.7/bin/bundle:22:in `load'

編集

Chromedriverは、テスト中に同じセッションIDを繰り返し再利用します。これが初めてテストに合格する理由ですが、もう一度開始した場合、chromedriverはまったく同じセッションIDを使用します。これが問題の原因だと思います。 Seleniumのアクションをログに記録しましたが、DELETEが送信されるため、理解できません。

2019-05-10 08:24:53 INFO Selenium -> POST session
2019-05-10 08:24:53 INFO Selenium    >>> http://127.0.0.1:9517/session | {"desiredCapabilities":{"browserName":"chrome","version":"","platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,"takesScreenshot":false,"nativeEvents":false,"rotatable":false},"capabilities":{"firstMatch":[{"browserName":"chrome"}]}}
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":0,"value":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})","userDataDir":"/var/folders/_x/xj6qbw1n30z7pr18t52y1yjh0000gn/T/.com.google.Chrome.IyCrBu"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:64888"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Mac OS X","proxy":{},"rotatable":false,"setWindowRect":true,"strictFileInteractability":false,"takesHeapSnapshot":true,"takesScreenshot":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unexpectedAlertBehaviour":"ignore","version":"74.0.3729.131","webStorageEnabled":true}}
2019-05-10 08:24:53 INFO Selenium Detected OSS dialect.
2019-05-10 08:24:53 INFO Selenium -> POST session/b8a41525be337e1a029cf574285d2031/url
2019-05-10 08:24:53 INFO Selenium    >>> http://127.0.0.1:9517/session/b8a41525be337e1a029cf574285d2031/url | {"url":"http://127.0.0.1:50711/"}
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":6,"value":{"message":"invalid session id\n  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.14.3 x86_64)"}}
2019-05-10 08:24:53 INFO Selenium -> DELETE session/b8a41525be337e1a029cf574285d2031/cookie
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":0,"value":null}
2019-05-10 08:24:53 INFO Selenium -> POST session/b8a41525be337e1a029cf574285d2031/url
2019-05-10 08:24:53 INFO Selenium    >>> http://127.0.0.1:9517/session/b8a41525be337e1a029cf574285d2031/url | {"url":"about:blank"}
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":0,"value":null}
2019-05-10 08:24:53 INFO Selenium -> POST session/b8a41525be337e1a029cf574285d2031/elements
2019-05-10 08:24:53 INFO Selenium    >>> http://127.0.0.1:9517/session/b8a41525be337e1a029cf574285d2031/elements | {"using":"xpath","value":"/html/body/*"}
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":0,"value":[]}
  User log in (FAILED - 1)

Failures:

  1) Test Feature User log in
     Failure/Error: visit root_path

     Selenium::WebDriver::Error::NoSuchDriverError:
       invalid session id
         (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.14.3 x86_64)
     # ./spec/features/test_spec.rb:8:in `block (2 levels) in <top (required)>'

Finished in 4.85 seconds (files took 11.27 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/test_spec.rb:4 # Test Feature User log in

2019-05-10 08:24:53 INFO Selenium -> DELETE session/b8a41525be337e1a029cf574285d2031
2019-05-10 08:24:53 INFO Selenium <- {"sessionId":"b8a41525be337e1a029cf574285d2031","status":0,"value":null}
16
Vincent Rolea

私は何がうまくいかなかったのかを見つけました。

ライブラリを使用して、最初に作成された後のテスト中にAPI応答をキャッシュします。

問題は、ドライバーがセッションIDを取得する要求を送信することです。これが、初めてテストに合格した理由です。ライブラリは毎回同じセッションIDを持つドライバからの応答をキャッシュしたため、Chromeからのエラーが発生しました。

このようなライブラリ(VCR、ephemeral_response)を使用していて、同様のエラーが発生する場合、これは調査したい問題です。

6
Vincent Rolea

最初に気付くのは、3年前のバージョンのカピバラと新しいバージョンのSelenium-webdriverChrome、およびchromedriverを使用していることです。 Selenium-webdriverはSemVerに準拠していないため、これらが正しく機能することを期待するのは簡単ではありません。あなたはおそらくカピバラをアップグレードしたいでしょう。

多くの場合、このエラーはChromeのリソースの問題が原因で発生します。 MacOSで実行しているように見えるため、これをコンテナーで実行している場合ほどではありません。ただし、disable-dev-shm-usage chromeオプションを追加したり、ウィンドウサイズを小さくしたりして、エラーが解消されるかどうかを確認しても問題ありません。再起動してみることもできます。 。

さらに、他のいくつかの可能性があります

  1. すでにセッションを閉じているAfterブロックが登録されています-Afterブロックをコメントアウトして、問題が解消するかどうかを確認してください

  2. Chromedriver 74のバグ(そのうちいくつかは報告されています- https://bugs.chromium.org/p/chromedriver/issues/detail?id=2885 など)-にロールバックしてみてくださいchromeおよびchromedriver 73を実行して、問題が解消するかどうかを確認します

3
Thomas Walpole

今日このエラーが発生しましたが、私にとってうまくいったのは、chromedriverのバージョンを最新のバージョンからchrome自分のマシンにインストールしたバージョン)にダウングレードすることでした。

0