Watir: get sometimes a Net::ReadTimeout error by launching chrome browser

瘦欲@ 提交于 2020-01-14 19:04:06

问题


I just use a watir script to download sequential status infos from a server. In most cases it works fine, but sometimes I get an Net::ReadTimeout error. I don't know why?

Code:

require "rubygems"
require "watir"
Watir.default_timeout = 180     # seconds – default is 60
prefs = { :download => { :prompt_for_download => false, :default_directory => path } }
browser = Watir::Browser.new :chrome, :switches => %w[--no-sandbox], :prefs => prefs
browser.goto 'https://www...'
...

Error Message:

/usr/lib/ruby/2.3.0/net/protocol.rb:158:in `rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)   
    from /usr/lib/ruby/2.3.0/net/protocol.rb:136:in `readuntil' 
    from /usr/lib/ruby/2.3.0/net/protocol.rb:146:in `readline'  
    from /usr/lib/ruby/2.3.0/net/http/response.rb:40:in `read_status_line'
    from /usr/lib/ruby/2.3.0/net/http/response.rb:29:in `read_new'
    from /usr/lib/ruby/2.3.0/net/http.rb:1437:in `block in transport_request'  
    from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `catch'
    from /usr/lib/ruby/2.3.0/net/http.rb:1434:in `transport_request'from /usr/lib/ruby/2.3.0/net/http.rb:1407:in `request'
    from /usr/lib/ruby/2.3.0/net/http.rb:1400:in `block in request'
    from /usr/lib/ruby/2.3.0/net/http.rb:853:in `start' 
    from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:103:in `response_for'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/default.rb:57:in `request' 
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'   
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:653:in `raw_execute'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:124:in `create_session'
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/remote/bridge.rb:88:in `initialize'  
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/chrome/bridge.rb:41:in `initialize'  
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `new'  
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver/common/driver.rb:61:in `for' 
    from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.1/lib/selenium/webdriver.rb:82:in `for'
    from /var/lib/gems/2.3.0/gems/watir-6.0.2/lib/watir/browser.rb:46:in `initialize'   
    from /var/www/jobs/ubuntu.rb:110:in `new'from /var/www/jobs/ubuntu.rb:5:in `<main>'

I just looking for a reason on this?

Is it possible the customize the settings on firefox? What is wrong?

  • Watir Version: 6.0.2
  • Selenium Version: 3.0.1
  • Browser Chrome Version: 57.0.2987.110
  • Chrome Driver Version: 2.29.461571
  • OS Version: Ubuntu 16.04.3 LTS

回答1:


I had a similar problem when running my Selenium Webdriver tests on our Ubuntu Jenkins build server, but I never experienced this locally on my Windows PC. Like your problem, it was an intermittent issue. I spent quite a lot of time researching it and couldn't get to the bottom of it, I did however put it down to a Ruby/ Ubuntu issue rather than an issue with the test, because of this, I decided to rescue the Net::ReadTimeout error and retry. Since implementing the following example, I haven't experienced this problem again.

     attempts = 0  # has to be outside the begin/rescue to avoid infinite loop
  begin
  profile = Selenium::WebDriver::Chrome::Profile.new
  $driver = Selenium::WebDriver.for :chrome, :profile => profile,
  $driver.manage.window.resize_to(1280, 720)
  rescue Net::ReadTimeout => e
    if attempts == 0
      attempts += 1
      retry
    else
      raise
    end
  end

You should be able to briefly modify the above example to work with Watir. It basically captures the error and retries/ re-runs the test.




回答2:


First of all, Watir.default_timeout has nothing to do with error you have stated, So even if you increase the time of default_timeout, nothing would happen in this place, Watir.default_timeout is applicable only when you find an element, not for page_load.

Second off, this problem only exist in Ruby Selenium Binding, not in Java Selenium Binding, for an example, If you set

driver.manage.timeouts.page_load=120 (WATIR doesn't provide any systax to this selenium equivalent, so to write this code in WATIR, please invoke b.driver.)

This time settings is only applicable for goto method, it's not affecting anything when you click a button and waiting for a page load, the default timeout for page_load is 60 seconds, that would anyhow wait for 60 seconds, but what you set doesn't affect or change this 60 seconds. But this problem is not there for Selenium Java Binding, it's working properly.

Okay, the question is, you are using it for goto so why not you can use the page_load to set the time?

Actually you can decrease the time, but you can't increase the time beyond 60 seconds. But I found some workaround for this problem, but I strongly recommend you to file a bug in ruby selenium binding.

So it's not a WATIR problem, it's the problem in Ruby selenium binding.




回答3:


Finally i tested also the solution with firefox and get the described error:

/var/lib/gems/2.1.0/gems/selenium-webdriver-3.0.1/lib/seleni‌​um/webdriver/remote/‌​response.rb:69:in 'assert_ok': 
TypeError: Given platformVersion [object String] "any", but current platform version is [object String] "3.16.0-4-amd64"
(Selenium::WebDriver::Error::SessionNotCreatedError)

It seems to be a problem with a specific firefox and geckodriver version. I tested many combinations. This versions work without the TypeError:

  • Firefox 51.0.1
  • geckodriver 0.11.1

Thanks to dan.brown



来源:https://stackoverflow.com/questions/47452276/watir-get-sometimes-a-netreadtimeout-error-by-launching-chrome-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!