Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver Error: invalid session id

Tags:

I use Selenium WebDriver and Chrome to do feature testing in my app. I have already successfully setup multiple rails app with rspec, capybara and selenium, but I can't get why this one does not work.

Here's the problem: When I run the feature tests for the first time, it works according to plan. However, if I run it a second time, selenium crashes with the following message:

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)

I might add that feature tests work perfectly in other apps, so this is not a Chrome/chromedriver compatibility issue.

I have been working on this for days now and I cannot figure out what's happening

Here's my config:

  • selenium-webdriver (3.141.0)
  • capybara (2.7.1)
  • Chrome 74 and 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  

Stacktrace:

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

EDIT

Chromedriver reuse the same session id over and over again over the tests. This is why the first time, the tests pass but if I start again, chromedriver will use the exact same session id which is what I think cause the problem. I logged Selenium's actions, and it does send DELETE so I don't understand.

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} 
like image 600
Vincent Rolea Avatar asked May 06 '19 09:05

Vincent Rolea


People also ask

What is Selenium session ID?

A session id is a distinctive number that is given to the webdriver by the server. This number is utilized by the webdriver to establish communication with the browser. The commands in our Selenium tests are directed to the browser with the help of this session id.

How do I start a new session in Selenium?

We can open a new window on a browser with Selenium webdriver. There are multiple ways to achieve this. Selenium can execute commands in Javascript with the help of the execute_script() method which is one of the ways of opening a new window. Then we shall use switch_to.

What is Selenium WebDriver for?

Selenium WebDriver is a web framework that permits you to execute cross-browser tests. This tool is used for automating web-based application testing to verify that it performs expectedly. Selenium WebDriver allows you to choose a programming language to create test scripts.


2 Answers

I found what went wrong.

We are using a library to cache api response during test after they are made for the first time.

The problem is, the driver sends a request to get a session id. This is why the first time the tests were passing. The library cached the response from the driver which had the same session id everytime, hence the error from chrome.

If you're using such libraries (VCR, ephemeral_response) and get similar error this is something you might want to investigate

like image 81
Vincent Rolea Avatar answered Oct 07 '22 10:10

Vincent Rolea


The first thing I notice is that you're using a 3 year old version of Capybara with new versions of selenium-webdriver, Chrome, and chromedriver. Since selenium-webdriver doesn't follow SemVer expecting those to work correctly together is a stretch. You probably want to upgrade Capybara.

Often this error is caused by resource issues with Chrome. Since you appear to be running on MacOS that's not as likely as if you were running this in containers. However it wouldn't hurt to try adding the disable-dev-shm-usage chrome option, and/or setting the window size smaller to see if the error goes away. You could also just try a reboot.

Beyond that a couple of other potentials are

  1. You have an after block registered that has already closed the session - comment out the after block and see if the issue goes away

  2. A bug in chromedriver 74 (of which a few have been reported - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2885, etc) - try rolling back to chrome and chromedriver 73 to see if the issue goes away

like image 33
Thomas Walpole Avatar answered Oct 07 '22 10:10

Thomas Walpole