Search code examples
ruby-on-railsseleniumselenium-webdrivercucumberwindows-subsystem-for-linux

Selenium Net::ReadTimeout on tests that pass instantly without @javascript tag - Ruby Cucumber tests


FINAL EDIT: I gave up and just did a full reinstallation of WSL2 and everything. Worked great. So if you're somehow dealing with this same problem, a hard reset may be a viable option.

I have already looked at many previous Stack Overflow posts, most notably this one whose second solution is echoed across most other posts on the topic, which is to extend the internal timeout to allot more time for the browser to load pages that take more than the default 60sec.

The Cucumber tests I'm running are small (the one I'm using as a baseline for this is 4 scenarios with 16 steps) and pass virtually instantly when not using Selenium, the pages are mostly static and I just want to be able to see it run+process popups in future tests, so I don't need more load time.

These tests were all working perfectly fine a few months ago (June), but when I reopened the same repo, completely unmodified now I'm unable to run any of the tests with selenium - it doesn't even open the browser anymore when run. As such, I get the feeling it doesn't have to do with my project settings, because none of it has changed. Even so, I've uninstalled the gems and reinstalled them, updated them, all to no avail. I don't know what local system settings/environment variables could have changed during this time, as I work on the app exclusively through WSL2, which I haven't touched since the last time I opened this specific project. Any ideas on this front would be very welcome.

The only configuration I've done for Capybara is setting Capybara.javascript_driver to either :selenium or :selenium_headless between testing sessions in my env.rb file, everything else is running default. My firefox and geckodriver versions are compatible.

Versions:

  • Ubuntu - 20.04.1 LTS
  • Ruby - 2.5.3
  • Firefox - 92.0
  • Geckodriver - 0.29.1
  • xfce4 - 4.14 (ran apt list -a xfce4, as xfce4-about gave me an error: 17:02:48.578: No vendor information found in "/usr/share/xfce4/vendorinfo".

Relevant (?) Gems :

  • selenium-webdriver (4.0.0.rc1)
  • webdriver (0.18.0)
  • cucumber (7.0.0)
  • cucumber-rails (2.4.0)

Please let me know if more information of any type is required, thank you.

EDIT: Relevant Github repos: last working version from a few months ago, most recent development branch as of this post

EDIT 2,4,5: Logs for one Cucumber scenario after setting geckodriver log level to trace:

2021-09-15 17:42:19 DEBUG Selenium Executing Process ["/usr/bin/geckodriver", "--port=4444"]
2021-09-15 17:42:19 DEBUG Selenium polling for socket on ["127.0.0.1", 4444]
1631752939382   geckodriver     INFO    Listening on 127.0.0.1:4444
2021-09-15 17:42:19 WARN Selenium [DEPRECATION] [:browser_options] :options as a parameter for driver initialization is deprecated. Use :capabilities with an Array of value capabilities/options if necessary instead.
2021-09-15 17:42:19 INFO Selenium -> POST session
2021-09-15 17:42:19 INFO Selenium    >>> http://127.0.0.1:4444/session | {"capabilities":{"alwaysMatch":{"browserName":"firefox","moz:firefoxOptions":{"log":{"level":"trace"}}}}}
2021-09-15 17:42:19 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/4.0.0.rc1 (ruby linux)", "Content-Length"=>"105"}
1631752939650   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "--marionette" "-no-remote" "-profile" "/tmp/rust_mozprofileqR2HiM"
1631752939651   geckodriver::marionette DEBUG   Waiting 60s to connect to browser on 127.0.0.1:46793
Net::ReadTimeout (Net::ReadTimeout)
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/protocol.rb:181:in `rbuf_fill'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/protocol.rb:157:in `readuntil'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/protocol.rb:167:in `readline'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http/response.rb:40:in `read_status_line'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http/response.rb:29:in `read_new'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http.rb:1494:in `block in transport_request'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http.rb:1491:in `catch'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http.rb:1491:in `transport_request'
/usr/share/rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/net/http.rb:1464:in `request'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/remote/http/default.rb:124:in `response_for'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/remote/http/default.rb:77:in `request'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/remote/bridge.rb:589:in `execute'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/remote/bridge.rb:52:in `create_session'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/common/driver.rb:338:in `create_bridge'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/common/driver.rb:73:in `initialize'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/common/driver.rb:53:in `new'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver/common/driver.rb:53:in `for'
/usr/share/rvm/gems/ruby-2.5.3/gems/selenium-webdriver-4.0.0.rc1/lib/selenium/webdriver.rb:87:in `for'
/home/nacho/Github/cs370/features/support/env.rb:18:in `<top (required)>'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/glue/registry_and_more.rb:121:in `require'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/glue/registry_and_more.rb:121:in `load_code_file'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime/support_code.rb:142:in `load_file'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime/support_code.rb:81:in `block in load_files!'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime/support_code.rb:80:in `each'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime/support_code.rb:80:in `load_files!'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime.rb:260:in `load_step_definitions'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/runtime.rb:72:in `run!'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/lib/cucumber/cli/main.rb:29:in `execute!'
/usr/share/rvm/gems/ruby-2.5.3/gems/cucumber-7.0.0/bin/cucumber:9:in `<top (required)>'
/usr/share/rvm/gems/ruby-2.5.3/bin/cucumber:23:in `load'
/usr/share/rvm/gems/ruby-2.5.3/bin/cucumber:23:in `<main>'
/usr/share/rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
/usr/share/rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'

EDIT 3: I've been poring through the log and googling various terms/lines, I'm not really coming up with too much that I know how to work with, though. A few things I've done:

  • Connect to 127.0.0.1:35213 and its variants, as it changes each time I run the tests, and saw a working version of my app
  • Tried to connect to the various sockets it was listening to like 127.0.0.1:4487 and 127.0.0.1:4487/session which stays the same between tests, but it would either a) not load or b) return a blank page with the text HTTP method not allowed in plain HTML

Solution

  • I gave up trying to fix anything and just uninstalled Ubuntu and reinstalled it, went through the full setup process again but omitted xfce4 because I realized I didn't need it for my purposes. Fresh start worked out, wish I'd done this three hours in instead of four days in. Live and learn, I suppose.