6

I get the following error when using selenium webdrivers on heroku. (rspec->capybara->selenium)

Net::ReadTimeout: Net::ReadTimeout with #<TCPSocket:(closed)>

I have the heroku-buildpack-google-chrome buildpack, with webdrivers-gem.

And have the following block in spec setup:

chrome_shim = ENV.fetch("GOOGLE_CHROME_SHIM", nil)

Selenium::WebDriver::Chrome.path = chrome_shim

chrome_opts = { "chromeOptions" => { "binary" => chrome_shim } }

Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(
      app,
      browser: :chrome,
      desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts)
    )
end

Capybara.javascript_driver = :headless_chrome

Webdrivers.logger.level = :DEBUG output is here https://gist.github.com/IanVaughan/3e0c50d2fa4a60e672b96f6726fbbb8c

capybara (3.30.0)
webdrivers (4.2.0)
selenium-webdriver (3.142.7)

Full stack trace: https://gist.github.com/IanVaughan/09b31613833d965ee4f3b7d1e48fd1e2

The spec I'm running is :

RSpec.feature 'User signup flow', :js do
  scenario 'Visits home page to signup' do
    visit root_path
    new_window = window_opened_by { click_link 'Sign Up', match: :first }
    within_window new_window do
      expect(page).to have_text('New Enquiry', wait: 5)
    end
  end
5
  • Put the actual versions of gems used - putting the limits (capybara >=2.15) doesn't actually tell us what versions you're using (also put the selenium-webdriver version). Also when do you get that error? Show the stacktrace. Commented Jan 15, 2020 at 21:10
  • @ThomasWalpole thanks for pointing that out, good point, I've added the gem versions as requested. And added full stack trace. Cheers Commented Jan 15, 2020 at 21:54
  • From the stacktrace selenium is hanging trying to get window handles - which would imply a chromedriver/chrome issue - can you show your whole test scenario just to confirm nothing strange is being done? Commented Jan 15, 2020 at 23:06
  • @ThomasWalpole I've added the spec! Commented Jan 16, 2020 at 9:29
  • 1
    Sounds like a chromedriver bug - check the chromedriver projects issues Commented Jan 16, 2020 at 19:28

2 Answers 2

3

If the timeout is happening during your apps first request, while the apps doing something onetime (compiling assets, etc), then you may need to increase the allowed read timeout

Capybara.register_driver :selenium do |app|
    Capybara::Selenium::Driver.new(
      ...
      timeout: 60 # defaults to 30 IIRC
    )
end
Sign up to request clarification or add additional context in comments.

2 Comments

Good idea, it's odd though because locally the test runs within 3 seconds. And when run on Heroku it waits for ages anyway, around a minute, and then fails. I tried this timeout setting and it didnt help, cheers
We're getting the same problem @IanVaughan, did you get this resolved? Did you try Kiran's suggestion above? Super annoying, it's only intermittent for us though.
-1

It could be possibly the cookies are cleared after 30 sec in headless mode

Add this in chrome options and try if its works:)

--enable-features=NetworkService,NetworkServiceInProcess

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.