SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.19k stars 8.11k forks source link

[🐛 Bug]: error from remote server causes a secondary error in Ruby library #14415

Closed jonleighton closed 1 week ago

jonleighton commented 3 weeks ago

What happened?

An error from a remote Selenium server is not correctly reported when using the selenium-webdriver v4.23.0 library in Ruby.

It appears that a bug in the selenium-webdriver exception handling code causes another exception to be raised.

Note that this problem does not occur in the previous v4.22.0 version.

How can we reproduce the issue?

I can reproduce by deliberately creating a situation where the client cannot obtain a new session within the timeout.

In one terminal, start selenium via a Docker container:

docker run \
  --rm \
  -p "4444:4444" \
  --shm-size="2g" \
  -e SE_SESSION_REQUEST_TIMEOUT=1 \
  -e SE_NODE_MAX_SESSIONS=1 \
  selenium/standalone-chromium:latest

In another terminal, run the following Ruby script:

# test.rb

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "selenium-webdriver", "4.23.0"
end

2.times.each do
  options = Selenium::WebDriver::Options.chrome
  driver = Selenium::WebDriver.for :remote, url: "http://localhost:4444/wd/hub", options: options
  driver.navigate.to "http://google.com"
end

Relevant log output

/Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:61:in `set_backtrace': backtrace must be Array of String (TypeError)

          cause.set_backtrace(backtrace)
                              ^^^^^^^^^
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:61:in `add_cause'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:41:in `error'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:101:in `new'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:101:in `create_response'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/default.rb:103:in `request'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:67:in `call'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/bridge.rb:675:in `execute'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/bridge.rb:76:in `create_session'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/driver.rb:323:in `block in create_bridge'
    from <internal:kernel>:90:in `tap'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/driver.rb:322:in `create_bridge'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/driver.rb:73:in `initialize'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/driver.rb:38:in `initialize'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/driver.rb:57:in `new'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/driver.rb:57:in `for'
    from /Users/jon/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver.rb:89:in `for'
    from test.rb:10:in `block in <main>'
    from test.rb:8:in `times'
    from test.rb:8:in `each'
    from test.rb:8:in `<main>'

Operating System

macOS Sonoma

Selenium version

Ruby 4.23.0

What are the browser(s) and version(s) where you see this issue?

Chromium 127.0

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 127.0.6533.119

Are you using Selenium Grid?

No response

github-actions[bot] commented 3 weeks ago

@jonleighton, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

jonleighton commented 3 weeks ago

14170 probably introduced this problem. CC-ing those involved: @p0deje @ioquatix @aguspe

aguspe commented 3 weeks ago

Thank you so much @jonleighton for raising this, I will pick this up and investigate later today

aguspe commented 3 weeks ago

This is my draft PR to fix the issue #14433, I will improve the test later today and put it up for review