web-dev-qa-db-fra.com

Erreur Selenium WebDriver: identifiant de session non valide

J'utilise Selenium WebDriver et Chrome pour effectuer des tests de fonctionnalités dans mon application. J'ai déjà configuré avec succès plusieurs applications Rails avec rspec, capybara et Selenium, mais je peux ne comprends pas pourquoi celui-ci ne fonctionne pas.

Voici le problème: lorsque j'exécute les tests de fonctionnalité pour la première fois, cela fonctionne comme prévu. Cependant, si je l'exécute une deuxième fois, Selenium se bloque avec le message suivant:

Selenium :: WebDriver :: Error :: NoSuchDriverError: identifiant de session non valide (Informations sur le pilote: chromedriver = 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729 @ {# 29}), plateforme = Mac OS X 10.14.3 x86_64)

Je pourrais ajouter que les tests de fonctionnalité fonctionnent parfaitement dans d'autres applications, il ne s'agit donc pas d'un problème de compatibilité Chrome/chromedriver.

J'y travaille depuis des jours maintenant et je n'arrive pas à comprendre ce qui se passe

Voici ma config:

  • Sélénium-Webdriver (3.141.0)
  • capybara (2.7.1)
  • Chrome 74 et 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

Trace de la pile:

# ./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'

ÉDITER

Chromedriver réutilise le même identifiant de session à plusieurs reprises au cours des tests. C'est pourquoi la première fois, les tests réussissent, mais si je recommence, chromedriver utilisera exactement le même identifiant de session qui est à mon avis la cause du problème. J'ai enregistré les actions de Selenium, et cela envoie DELETE donc je ne comprends pas.

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

J'ai trouvé ce qui n'allait pas.

Nous utilisons une bibliothèque pour mettre en cache la réponse api pendant le test après leur première création.

Le problème est que le pilote envoie une demande pour obtenir un identifiant de session. C'est pourquoi la première fois, les tests ont réussi. La bibliothèque a mis en cache la réponse du pilote qui avait à chaque fois le même identifiant de session, d'où l'erreur de Chrome.

Si vous utilisez de telles bibliothèques (VCR, ephemeral_response) et obtenez une erreur similaire, c'est quelque chose que vous voudrez peut-être étudier

6
Vincent Rolea

La première chose que je remarque, c'est que vous utilisez une version de 3 ans de Capybara avec de nouvelles versions de Selenium-webdriver, Chrome et chromedriver. Puisque Selenium-webdriver ne suit pas SemVer s'attendre à ce que ceux-ci fonctionnent correctement ensemble est un tronçon. Vous souhaitez probablement mettre à niveau Capybara.

Cette erreur est souvent due à des problèmes de ressources avec Chrome. Étant donné que vous semblez fonctionner sur MacOS, ce n'est pas aussi probable que si vous l'exécutiez dans des conteneurs. Mais cela ne ferait pas de mal d'essayer d'ajouter le disable-dev-shm-usage chrome option, et/ou définition de la taille de la fenêtre plus petite pour voir si l'erreur disparaît. Vous pouvez également essayer de redémarrer.

Au-delà, quelques autres potentiels sont

  1. Vous avez enregistré un bloc après qui a déjà fermé la session - commentez le bloc après et voyez si le problème disparaît

  2. Un bogue dans chromedriver 74 (dont quelques-uns ont été signalés - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2885 , etc) - essayez de revenir à chrome et chromedriver 73 pour voir si le problème disparaît

3
Thomas Walpole

J'ai eu cette erreur aujourd'hui et ce qui a fonctionné pour moi a été de rétrograder la version chromedriver de la dernière à la version chrome que j'ai installée sur ma machine.

0
Alexander Chuzhoy