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

System tests not working on Rails 7.1.3 running on a remote machine/docker container. #50827

Closed
srabuini opened this issue Jan 21, 2024 · 4 comments · Fixed by #51479
Closed

Comments

@srabuini
Copy link

Steps to reproduce

I've been running my system tests using a remote browser (on a docker container) since Rails 7.0 without a problem, with the following set up.

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium,
            using: :chrome,
            screen_size: [1400, 1400],
            options: { browser: :remote,
                       url: 'http://chrome-server:4444' } do |driver_option|
    driver_option.add_argument 'disable-dev-shm-usage'
  end

It looks like the problem was introduced in #49908 and related issues/fixes.

I fixed it locally just monkeypatching Selenium::Webdriver::DriverFinder.path just to return nil.

Having a look at the code, I think that it would be nice to avoid Browser#preload when browser is :remote in:

If you think it's the right way to tackle it, I could post a fix.

Actual behavior

After a while, an exception is raised:

Selenium::WebDriver::Error::SessionNotCreatedError: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: no chrome binary at /root/.cache/selenium/chrome/linux64/120.0.6099.109/chrome 
Host info: host: 'c3260b1b08ce', ip: '192.168.16.3'
Build info: version: '4.10.0', revision: 'c14d967899'
System info: os.name: 'Linux', os.arch: 'aarch64', os.version: '6.5.11-linuxkit', java.version: '11.0.18'
Driver info: driver.version: unknown
Build info: version: '4.10.0', revision: 'c14d967899'
System info: os.name: 'Linux', os.arch: 'aarch64', os.version: '6.5.11-linuxkit', java.version: '11.0.18'
Driver info: driver.version: unknown
    [remote server] org.openqa.selenium.grid.node.config.DriverServiceSessionFactory(DriverServiceSessionFactory.java):210:in `apply'
    [remote server] org.openqa.selenium.grid.node.config.DriverServiceSessionFactory(DriverServiceSessionFactory.java):69:in `apply'
    [remote server] org.openqa.selenium.grid.node.local.SessionSlot(SessionSlot.java):147:in `apply'
    [remote server] org.openqa.selenium.grid.node.local.LocalNode(LocalNode.java):467:in `newSession'
    [remote server] org.openqa.selenium.grid.distributor.local.LocalDistributor(LocalDistributor.java):643:in `startSession'
    [remote server] org.openqa.selenium.grid.distributor.local.LocalDistributor(LocalDistributor.java):560:in `newSession'
    [remote server] org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable(LocalDistributor.java):814:in `handleNewSessionRequest'
    [remote server] org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable(LocalDistributor.java):773:in `lambda$run$1'
    [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecutor.java):1128:in `runWorker'
    [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPoolExecutor.java):628:in `run'
    [remote server] java.lang.Thread(Thread.java):829:in `run'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/response.rb:55:in `assert_ok'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/default.rb:103:in `request'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/bridge.rb:601:in `execute'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/bridge.rb:53:in `create_session'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:317:in `block in create_bridge'
    <internal:kernel>:90:in `tap'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:316:in `create_bridge'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:74:in `initialize'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/driver.rb:38:in `initialize'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:57:in `new'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:57:in `for'
    /usr/local/bundle/ruby/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver.rb:89:in `for'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:83:in `browser'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/driver.rb:55:in `block in register_selenium'
    <internal:kernel>:90:in `tap'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/driver.rb:54:in `register_selenium'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/driver.rb:41:in `block in register'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara/session.rb:105:in `driver'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara/session.rb:91:in `initialize'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara.rb:421:in `new'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara.rb:421:in `block in session_pool'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara.rb:317:in `current_session'
    /usr/local/bundle/ruby/3.2.0/gems/capybara-3.39.2/lib/capybara/dsl.rb:46:in `page'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:106:in `save_image'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:36:in `take_screenshot'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb:47:in `take_failed_screenshot'
    /usr/local/bundle/ruby/3.2.0/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb:8:in `before_teardown'

System configuration

Rails version: 7.1..3

Ruby version: 3.2.2 (2023-03-30 revision e51014f9c0) [aarch64-linux]

@muhme
Copy link

muhme commented Jan 25, 2024

Hi @srabuini thanks for your explanation in detail, I ran into the same issue with upgrading to Rails 7.1.3 / ruby 3.2.3 and was able to continue working with test:system by the hack commenting out line 19 @browser.preload 👍

@hahmed
Copy link
Contributor

hahmed commented Jan 28, 2024

This issue sounds similar to what was reported in #47706, could you try that and see if it resolves your issue? I could be wrong, but I don't think you need to patch rails, you should be able to update the args you are sending to driven_by.

@muhme
Copy link

muhme commented Jan 29, 2024

@hahmed thanks for investigating, I changed using: :chrome in using: :headless_chrome, but still getting

  • no chrome binary at /root/.cache/selenium/chrome/linux64/121.0.6167.85/chrome

My original ApplicationSystemTestCase configuration is:

  driven_by :selenium, using: :chrome, screen_size: [1200, 1800], options: { browser: :remote, url: "http://chrome:4444" }
  
  def setup
    Capybara.app_host = "http://rails:3100"
    Capybara.default_max_wait_time = 10 # default 2 seconds are not long enough for translations
    Capybara.server_port = 3100       # puma listening port 3100 on TEST 
    Capybara.server_host = "0.0.0.0"
    Capybara.default_driver = :selenium # not using default :rack_test w/o JavaScript
    super
  end

Instead, if I comment out line 19 @browser.preload in file

  • /usr/local/bundle/gems/actionpack-7.1.3/lib/action_dispatch/system_testing/driver.rb

everything is working.

I am not sure, was that the test or what should I try to change?

@srabuini
Copy link
Author

srabuini commented Jan 29, 2024

Hi @hahmed, it might be similar, but not exactly the same. It changed when the way to find the driver_path changed. Instead of changing again that process, it could be simpler as avoiding preload when the driver is explicitly :remote.

@muhme I'd fixit with

@browser.preload unless @options[:browser] == :remote

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

Successfully merging a pull request may close this issue.

3 participants