Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run RSpec system specs without Chrome installed, even specifying Rack::Test explicitly #37410

Closed
dmolesUC opened this issue Oct 9, 2019 · 3 comments

Comments

@dmolesUC
Copy link

dmolesUC commented Oct 9, 2019

RSpec tests configured to run with Rack::Test can't be run in a container (or on a machine) without Chrome, because ActiveSupport::TestCase tries to load Chrome as soon as it's required, resulting in Webdrivers::BrowserNotFound.

Steps to reproduce

  1. Clone the repository: dmolesUC/rack_test_rails_6, consisting of a minimal Rails 6 app with one RSpec-based system test, configured to run with Rack::Test.

  2. Following the instructions in the README, stand up a Docker stack and attempt to run the specs.

    docker-compose up --pull && \
     docker-compose run --rm rails spec

Expected behavior

Spec runs with Rack::Test.

Actual behavior

Spec can't even be loaded, and fail with the following error:

Webdrivers::BrowserNotFound:
  Failed to find Chrome binary.
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chrome_finder.rb:21:in `location'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chrome_finder.rb:10:in `version'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chromedriver.rb:46:in `browser_version'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chromedriver.rb:106:in `release_version'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chromedriver.rb:32:in `latest_version'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/common.rb:135:in `correct_binary?'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/common.rb:91:in `update'
# /usr/local/bundle/ruby/2.6.0/gems/webdrivers-4.1.3/lib/webdrivers/chromedriver.rb:119:in `block in <main>'
# /usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/core_ext/object/try.rb:15:in `public_send'
# /usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/core_ext/object/try.rb:15:in `try'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/browser.rb:50:in `preload'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_testing/driver.rb:13:in `initialize'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_test_case.rb:159:in `new'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_test_case.rb:159:in `driven_by'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_test_case.rb:162:in `<class:SystemTestCase>'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_test_case.rb:114:in `<module:ActionDispatch>'
# /usr/local/bundle/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/system_test_case.rb:16:in `<main>'
# /usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
# /usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
# /usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
# /usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
# /usr/local/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
# /usr/local/bundle/ruby/2.6.0/gems/zeitwerk-2.2.0/lib/zeitwerk/kernel.rb:23:in `require'
# /usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/concern.rb:122:in `class_eval'
# /usr/local/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/concern.rb:122:in `append_features'
# ./spec/system/foos_spec.rb:3:in `<top (required)>'

System configuration

Rails version: 6.0.0

Ruby version: 2.6.4

sinsoku added a commit to sinsoku/rails that referenced this issue Oct 15, 2019
If you require "action_dispatch/system_test_case", the driven_by method
will be executed immediately.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_test_case.rb#L162

Then the preload method is called in SystemTesting::Driver#initialize.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/driver.rb#L13
* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/browser.rb#L46-L63

Therefore, a "Webdrivers::BrowserNotFound" error occurs in the browser
preloading when you run system tests witout Chrome.

This commit avoid the error by lazy configuring the driver.

ref: rails#37410
@sinsoku
Copy link
Contributor

sinsoku commented Oct 16, 2019

There are two causes of this issue.

  • System specs implicitly require 'action_dispatch/system_test_case' and driven_by(:selenium) is executed immediately in the file
  • driven_by(:selenium) is always called in rspec-rails

I fixed driver configuration to be lazy for #37476 and rspec/rspec-rails#2188.

Mr0grog added a commit to edgi-govdata-archiving/web-monitoring-db that referenced this issue Nov 1, 2019
We don't use Selenium at all, but Rails 6 requires it from the get-go no matter what. See this change: rails/rails@b21ef26

I think we're basically hitting a flavor of this issue: rails/rails#37410
...and fixes are still pending.
Mr0grog added a commit to edgi-govdata-archiving/web-monitoring-db that referenced this issue Nov 18, 2019
We don't use Selenium at all, but Rails 6 requires it from the get-go no matter what. See this change: rails/rails@b21ef26

I think we're basically hitting a flavor of this issue: rails/rails#37410
...and fixes are still pending.
sinsoku added a commit to sinsoku/rails that referenced this issue Nov 20, 2019
If users specify `driven_by(:rack_test)`, it uses Chrome by default arguments.
However, `Rack::Test` does not use a browser and does not need to be preloaded.

Furthermore, it occurs `Webdrivers::BrowserNotFound` when run in
a container (or a machine) without Chrome.

ref: rails#37410
y-yagi pushed a commit that referenced this issue Nov 20, 2019
* Allow system tests using Rack::Test to run without Chrome

If you require "action_dispatch/system_test_case", the driven_by method
will be executed immediately.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_test_case.rb#L162

Then the preload method is called in SystemTesting::Driver#initialize.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/driver.rb#L13
* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/browser.rb#L46-L63

Therefore, a "Webdrivers::BrowserNotFound" error occurs in the browser
preloading when you run system tests witout Chrome.

This commit avoid the error by lazy configuring the driver.

ref: #37410

* Don't preload the browser with :rack_test

If users specify `driven_by(:rack_test)`, it uses Chrome by default arguments.
However, `Rack::Test` does not use a browser and does not need to be preloaded.

Furthermore, it occurs `Webdrivers::BrowserNotFound` when run in
a container (or a machine) without Chrome.
@y-yagi
Copy link
Member

y-yagi commented Nov 20, 2019

Fixed by #37476.

@y-yagi y-yagi closed this as completed Nov 20, 2019
@maysam
Copy link

maysam commented Feb 17, 2020

I just wanted to mention here that I have similar problem, only that it works fine locally but chrome is required for rack_test when it is running on @circleci

y-yagi pushed a commit that referenced this issue Feb 23, 2020
* Allow system tests using Rack::Test to run without Chrome

If you require "action_dispatch/system_test_case", the driven_by method
will be executed immediately.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_test_case.rb#L162

Then the preload method is called in SystemTesting::Driver#initialize.

* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/driver.rb#L13
* https://github.com/rails/rails/blob/v6.0.0/actionpack/lib/action_dispatch/system_testing/browser.rb#L46-L63

Therefore, a "Webdrivers::BrowserNotFound" error occurs in the browser
preloading when you run system tests witout Chrome.

This commit avoid the error by lazy configuring the driver.

ref: #37410

* Don't preload the browser with :rack_test

If users specify `driven_by(:rack_test)`, it uses Chrome by default arguments.
However, `Rack::Test` does not use a browser and does not need to be preloaded.

Furthermore, it occurs `Webdrivers::BrowserNotFound` when run in
a container (or a machine) without Chrome.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants