我使用Selenium WebDriver和Chrome在我的应用程序中进行功能测试。我已经使用rspec,capybara和selenium成功设置了多个Rails应用程序,但是我不明白为什么这个不起作用。
这里是问题:当我第一次运行功能测试时,它按计划工作。但是,如果我第二次运行它,硒将崩溃,并显示以下消息:
Selenium :: WebDriver :: Error :: NoSuchDriverError: 无效的工作阶段编号 (驱动程序信息:chromedriver = 74.0.3729.6(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs / branch-heads / 3729 @ {#29}),platform = Mac OS X 10.14.3 x86_64)
我可能会补充说功能测试可以在其他应用程序中完美运行,因此这不是Chrome / chromedriver兼容性问题。
我已经为此工作了好几天,我无法弄清楚发生了什么
这是我的配置:
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'
编辑
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}
答案 0 :(得分:3)
我发现出了什么问题。
首次使用后,我们正在使用一个库在测试过程中缓存api响应。
问题是,驱动程序发送请求以获取会话ID。这就是为什么测试第一次通过。该库每次都会缓存来自具有相同会话ID的驱动程序的响应,因此会产生chrome错误。
如果您正在使用此类库(VCR,ephemeral_response)并且遇到类似错误,则可能需要调查
答案 1 :(得分:1)
我注意到的第一件事是您使用的是3年的Capybara版本,其中包含selenium-webdriver
,Chrome
和chromedriver
的新版本。由于selenium-webdriver
不遵循SemVer,因此期望它们能够正常工作是很困难的。您可能想要升级水豚。
此错误通常是由Chrome资源问题引起的。由于您似乎正在MacOS上运行,因此不太可能在容器中运行它。但是,尝试添加disable-dev-shm-usage
chrome选项和/或将窗口大小设置为较小以查看错误是否消失并没有什么坏处。您也可以尝试重新启动。
除了其他一些潜力之外
您注册了一个after block,它已经关闭了会话-注释掉after block,看看问题是否消失
chromedriver 74中的一个错误(已报告了一些错误-https://bugs.chromium.org/p/chromedriver/issues/detail?id=2885等)-尝试回滚到chrome和chromedriver 73,以查看问题是否消失
答案 2 :(得分:1)
无效的会话ID错误是服务器无法识别唯一的会话标识符时发生的WebDriver错误。如果会话已被删除或会话ID无效,则会发生这种情况。
答案 3 :(得分:0)
我今天遇到此错误,对我有用的是将chromedriver版本从最新降级到我在计算机上安装的chrome版本。