我正在使用在虚拟框中的Windows 8下作为服务安装的jenkins slave在firefox中运行Watir测试。
测试用例包括两个测试。当我手动运行它们时,一切都很好。当jenkins运行它们时,第一个测试总是成功,第二个测试总是失败,例外:Net::ReadTimeout: Net::ReadTimeout
。
我尝试过不同的测试代码和begin/rescue
块组合,但每次异常都是由浏览器对象方法引起的:
@browser.goto
@browser.execute_script
@browser.wait_until_present
@browser.close
...
设置和拆解是:
def teardown
@browser.close
end
def setup
profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension @extension_path
@browser = Watir::Browser.new :firefox, :profile => profile
end
gems版本:
watir (4.0.2)
selenium-webdriver (2.33.0)
我还尝试在启用了桌面交互的系统帐户下运行服务,并在本地用户帐户下运行。
错误日志之一:
> Net::ReadTimeout: Net::ReadTimeout
C:/Ruby200-x64/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill'
C:/Ruby200-x64/lib/ruby/2.0.0/net/protocol.rb:152:in `rbuf_fill'
C:/Ruby200-x64/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
C:/Ruby200-x64/lib/ruby/2.0.0/net/protocol.rb:144:in `readline'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http/response.rb:39:in `read_status_line'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http/response.rb:28:in `read_new'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1406:in `block in transport_request'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1403:in `catch'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1403:in `transport_request'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1376:in `request'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1369:in `block in request'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:852:in `start'
C:/Ruby200-x64/lib/ruby/2.0.0/net/http.rb:1367:in `request'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in `raw_execute'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in `execute'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:195:in `quit'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/bridge.rb:55:in `quit'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/driver.rb:168:in `quit'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/browser.rb:135:in `close'
C:/jenkins/workspace/tests_matrix/TEST_BROWSER/firefox/TEST_OS/windows8/build_script_win/tests/test_case2.rb:173:in `teardown'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1316:in `block in run'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1314:in `each'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1314:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit/testcase.rb:17:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:919:in `block in _run_suite'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:912:in `map'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:912:in `_run_suite'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:657:in `block in _run_suites'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:655:in `each'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:655:in `_run_suites'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:867:in `_run_anything'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1060:in `run_tests'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1047:in `block in _run'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1046:in `each'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1046:in `_run'
C:/Ruby200-x64/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:21:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:774:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:834:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/test/unit.rb:838:in `run'
C:/Users/test/AppData/Local/Temp/hudson2953103359547849695.sh:4:in `<main>'
答案 0 :(得分:0)
我也遇到了Net :: ReadTimeout错误,并且在捕获Net :: ReadTimeout错误之后刷新浏览器并尝试修复它,如下所示:
begin
@browser.goto WEBSITE
rescue Net::ReadTimeout
@browser.refresh
sleep 1 unless @browser.ready_state == "complete"
end
我认为如果您发布测试用例代码,可能会有助于达成解决方案。