Selenium driver can return Selenium::WebDriver::Error::ServerError during setup_exit_handler
chendo opened this issue · comments
Meta
Capybara Version: 3.39.2
Driver Information (and browser if relevant): Selenium, 4.10.0, Chromium
Expected Behavior
During exit, Capybara should try to clean up Selenium and not error.
Actual Behavior
Occasionally, we're seeing status code 404 (Selenium::WebDriver::Error::ServerError)
when the test suite is finishing and Capybara is cleaning up the Selenium session.
This could be some interaction with knapsack_pro
's dynamic queue mode, which we are using. However, it seems like the 404 response is due to the session already exited for whatever reason. It feels like this is equivalent to Selenium::WebDriver::Error::InvalidSessionIdError
but it's currently unclear why it doesn't return that instead.
Backtrace:
/usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:59:in `assert_ok': status code 404 (Selenium::WebDriver::Error::ServerError)
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
| from /app/spec/support/selenium_patches.rb:16:in `request'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:620:in `execute'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:187:in `quit'
| from /usr/local/bundle/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:173:in `quit'
| from /usr/local/bundle/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:293:in `quit'
| from /usr/local/bundle/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:519:in `block in setup_exit_handler'
```
We won't be ignoring errors during cleanup since they tend to indicate resource leakage and/or misbehaving tests. IMO people should fix the root cause rather than expecting Capybara to ignore/hide the errors.
Fair enough! We've patched the Driver#quit
to eat this error in our suite for the time being, as this only happens as the test is finishing, and we clean up the Selenium container right after this.