Watir:通过启动 chrome 浏览器有时会出现 Net::ReadTimeout 错误 [英] Watir: get sometimes a Net::ReadTimeout error by launching chrome browser
问题描述
我只是使用 watir 脚本从服务器下载顺序状态信息.在大多数情况下它工作正常,但有时我会收到 Net::ReadTimeout 错误.不知道为什么?
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?
代码:
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...'
...
错误信息:
/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>'
我只是在寻找原因?
是否可以在 Firefox 上自定义设置?怎么了?
Is it possible the customize the settings on firefox? What is wrong?
- Watir 版本:6.0.2
- 硒版本:3.0.1
- 浏览器 Chrome 版本:57.0.2987.110
- Chrome 驱动程序版本:2.29.461571
- 操作系统版本:Ubuntu 16.04.3 LTS
推荐答案
我在 Ubuntu Jenkins 构建服务器上运行 Selenium Webdriver 测试时遇到了类似的问题,但我从未在 Windows PC 本地遇到过这种问题.就像您的问题一样,这是一个间歇性问题.我花了很多时间研究它,但无法深入了解它,但我确实将其归结为 Ruby/Ubuntu 问题而不是测试问题,因此,我决定拯救网络::ReadTimeout 错误并重试.自从实施了下面的例子后,我再没有遇到过这个问题.
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
您应该能够简单地修改上面的示例以使用 Watir.它基本上捕获错误并重试/重新运行测试.
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.
这篇关于Watir:通过启动 chrome 浏览器有时会出现 Net::ReadTimeout 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!