Get ReadTimeout using webdrivers selenium on Heroku

1.4k views Asked by At

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
2

There are 2 answers

2
Thomas Walpole On

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
0
Kiran Reddy On

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