提问人:valcod3r 提问时间:3/4/2023 更新时间:3/6/2023 访问量:241
Gem::LoadError:无法激活 selenium-webdriver (>= 4.0.0) RSpec Rails 7
Gem::LoadError: can't activate selenium-webdriver (>= 4.0.0) RSpec Rails 7
问:
我遇到了一个奇怪的问题,selenium-webdriver 不尊重 gem 的选定版本号,并且导致我的规格总体上失败。我似乎无法阻止它,即使在卸载宝石并使用选定的版本重新安装它们之后。我在 docker 上运行所有这些,很难跟踪问题的来源。如何让 selenium-webdriver-3.142.7 成为运行验收测试的唯一选择?
错误:
Failures:
1) Landing Page Navigation shows header
Failure/Error: raise e
Gem::LoadError:
can't activate selenium-webdriver (>= 4.0.0), already activated selenium-webdriver-3.142.7. Make sure all dependencies are added to Gemfile.
# /usr/local/bundle/gems/bundler-2.4.1/lib/bundler/rubygems_integration.rb:276:in `block (2 levels) in replace_gem'
# /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_dispatch/system_testing/driver.rb:24:in `initialize'
# /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_dispatch/system_test_case.rb:159:in `new'
# /usr/local/bundle/gems/actionpack-7.0.2.2/lib/action_dispatch/system_test_case.rb:159:in `driven_by'
# /usr/local/bundle/gems/rspec-rails-6.0.1/lib/rspec/rails/example/system_example_group.rb:99:in `driven_by'
# /usr/local/bundle/gems/rspec-rails-6.0.1/lib/rspec/rails/example/system_example_group.rb:94:in `block in initialize'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:457:in `instance_exec'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:457:in `instance_exec'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:365:in `run'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:529:in `block in run_owned_hooks_for'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:528:in `each'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:528:in `run_owned_hooks_for'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:615:in `block in run_example_hooks_for'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:614:in `reverse_each'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:614:in `run_example_hooks_for'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:484:in `run'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:505:in `run_before_example'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:261:in `block in run'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:486:in `block in run'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
# /usr/local/bundle/gems/rspec-core-3.12.1/lib/rspec/core/example.rb:352:in `call'
# /usr/local/bundle/gems/rspec-rails-6.0.1/lib/rspec/rails/example/system_example_group.rb:120:in `block (2 levels) in <module:SystemExampleGroup>'
Gemfile
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem "rspec-rails"
gem "factory_bot_rails"
gem "faker"
end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'letter_opener_web', '~> 2.0'
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end
group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem 'selenium-webdriver', '~> 3.142.7'
gem "webdrivers"
end
docker-compose.yml
services:
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bin/rails s -p 3001 -b '0.0.0.0' && rails tailwindcss:watch"
volumes:
- .:/usr/src/app
- bundle:/usr/local/bundle
ports:
- "3001:3001"
- "80:80"
env_file:
- .env
environment:
- HISTFILE=/usr/src/app/log/.bash_history
- HUB_HOST=hub:4444
depends_on:
- db
- redis
hub:
image: selenium/hub:3.8.1
environment:
GRID_BROWSER_TIMEOUT: 10000 # 10 seconds
GRID_NEW_SESSION_WAIT_TIMEOUT: 20000
GRID_NODE_POLLING: 300
GRID_TIMEOUT: 10000
ports:
- "4444:4444"
node-chrome:
image: selenium/node-chrome:3.8.1
environment: &SELENIUM_NODE_ENV
HUB_HOST: hub
HUB_PORT: 4444
ports:
- "5901:5901"
volumes:
- /dev/shm:/dev/shm
水豚.rb
require 'capybara'
Capybara.register_driver :chrome_headless do |app|
chrome_capabilities = ::Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => { 'args': %w[no-sandbox headless disable-gpu window-size=1400,1400] })
if ENV['HUB_URL']
Capybara::Selenium::Driver.new(app,
browser: :remote,
url: "http://#{ENV['HUB_HOST']}/wd/hub",
capabilities: chrome_capabilities)
else
Capybara::Selenium::Driver.new(app,
browser: :chrome,
capabilities: chrome_capabilities)
end
end
答:
0赞
Luke Hill
3/6/2023
#1
没有看到你的gemfile.lock,很难说。但是错误告诉您您正在尝试加载 2 个冲突版本的 selenium-webdriver
评论
0赞
valcod3r
3/7/2023
当 docker 运行 selenium 时,有些事情发生了变化——它指向了错误的宝石。我只是要把它放在架子上,直到我找到 capybara/docker/selenium hub 的工作解决方案
0赞
Luke Hill
3/7/2023
跑gem list selenium-webdriver
评论