heroku / heroku-buildpack-google-chrome

Run (headless) Google Chrome on Heroku
298 stars 3 forks source link

Net::ReadTimeout via Selenium/Capybara #83

Open IanVaughan opened 4 years ago

IanVaughan commented 4 years ago

I keep getting Net::ReadTimeout: Net::ReadTimeout with #<TCPSocket:(closed)> when run via Capybara. I have the heroku-buildpack-google-chrome build pack, with webdrivers-gem.

It works when directly running on a heroku dyno (from localhost heroku ci:debug --pipeline release-pipeline):

$ irb
> require 'webdrivers'
> Selenium::WebDriver::Chrome.path = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
> driver = Selenium::WebDriver.for :chrome
> driver.navigate.to "http://google.com"
> puts driver.title
Google

But from rspec it errors (compacted log)

$ bundle exec rspec spec/features
...
     1.2) Failure/Error: (io = @io.to_io).wait_readable(@read_timeout) or raise Net::ReadTimeout.new(io)

          Net::ReadTimeout: Net::ReadTimeout with #<TCPSocket:(closed)>
          # /app/vendor/ruby-2.7.0/lib/ruby/2.7.0/net/protocol.rb:217:in `rbuf_fill'
          # /app/vendor/bundle/ruby/2.7.0/gems/webmock-3.7.6/lib/webmock/http_lib_adapters/net_http.rb:285:in `rbuf_fill'
          # /app/vendor/ruby-2.7.0/lib/ruby/2.7.0/net/protocol.rb:191:in `readuntil'
          # /app/vendor/bundle/ruby/2.7.0/gems/webmock-3.7.6/lib/webmock/http_lib_adapters
          # /app/vendor/bundle/ruby/2.7.0/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'

rspec config when ran on Heroku (not active when ran locally) :

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

  # Required for webdrivers
  Selenium::WebDriver::Chrome.path = chrome_shim

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

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

  Capybara.javascript_driver = :headless_chrome

Using

  gem 'capybara', '>= 2.15'
  gem 'webdrivers', '~> 4.0'

logs with Webdrivers.logger.level & Selenium::WebDriver.logger.level = :debug

I've cross posted this to SO as well https://stackoverflow.com/questions/59723188/get-readtimeout-using-webdrivers-selenium-on-heroku

juanmanuelramallo commented 4 years ago

Were you able to resolve this issue @IanVaughan ? I'm experiencing something similar

rslifka commented 4 years ago

Same issue here. If you expand your search a bit, you'll see that people have been confused for ages about Chrome --headless being up to 40x slower (the shim automatically applies the --headless (and other) parameters). It happens locally for me as well using --headless so I suspect it's more a Chrome issue than a Heroku issue.

laddhadhiraj commented 3 years ago

Is anyone find the solution for this at Heroku CI? I m also getting same issue at heroku CI for with capybara test cases

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