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
Ian Vaughan
  • 20,211
  • 13
  • 59
  • 79
  • 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. – Thomas Walpole Jan 15 '20 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 – Ian Vaughan Jan 15 '20 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? – Thomas Walpole Jan 15 '20 at 23:06
  • @ThomasWalpole I've added the spec! – Ian Vaughan Jan 16 '20 at 09:29
  • 1
    Sounds like a chromedriver bug - check the chromedriver projects issues – Thomas Walpole Jan 16 '20 at 19:28

2 Answers2

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
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • 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 – Ian Vaughan Jan 15 '20 at 22:05
  • 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. – Matt Powell Feb 10 '20 at 22:44
-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
Kiran Reddy
  • 120
  • 1
  • 6