我正在使用Ruby / Cucumber / Capybara / Chromedriver运行自动化测试。自动化测试由jenkins运行。奇怪的是,有时浏览器会打开,但是黑屏会出现Net :: ReadTimeout,浏览器没有关闭,所以占用了我的记忆。我想要实现的是,如果发生这种情况,必须关闭黑屏浏览器。有什么建议? 这是我在jenkins中遇到的错误:
Net::ReadTimeout (Net::ReadTimeout)
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:176:in `rbuf_fill'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:154:in `readuntil'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/protocol.rb:164:in `readline'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http/response.rb:40:in `read_status_line'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http/response.rb:29:in `read_new'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1446:in `block in transport_request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `catch'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1443:in `transport_request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1416:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1409:in `block in request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:877:in `start'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/2.4.0/net/http.rb:1407:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/default.rb:124:in `response_for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/default.rb:78:in `request'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/http/common.rb:63:in `call'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:645:in `raw_execute'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:109:in `create_session'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/bridge.rb:69:in `initialize'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/chrome/bridge.rb:42:in `initialize'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/driver.rb:61:in `new'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/driver.rb:61:in `for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver.rb:82:in `for'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/capybara-2.11.0/lib/capybara/selenium/driver.rb:22:in `browser'
/var/lib/jenkins/workspace/autotest/features/support/env.rb:12:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/rb_support/rb_language.rb:96:in `load'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/rb_support/rb_language.rb:96:in `load_code_file'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:142:in `load_file'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:84:in `block in load_files!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:83:in `each'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime/support_code.rb:83:in `load_files!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime.rb:253:in `load_step_definitions'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/runtime.rb:61:in `run!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/lib/cucumber/cli/main.rb:32:in `execute!'
/var/lib/jenkins/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/cucumber-2.4.0/bin/cucumber:8:in `<top (required)>'
/var/lib/jenkins/.rbenv/versions/2.4.0/bin/cucumber:22:in `load'
/var/lib/jenkins/.rbenv/versions/2.4.0/bin/cucumber:22:in `<main>'
答案 0 :(得分:0)
跟踪错误,确切地讲,此错误来自您的代码,然后
begin
<driver execution code>
rescue Net::ReadTimeout
@driver.quit
end
这应该可以捕获错误并根据需要关闭会话。
我所做的是编写一个单独的方法来处理错误
def rescue_exceptions
begin
yield
rescue Selenium::WebDriver::Error::NoSuchElementError,
Selenium::WebDriver::Error::UnknownError,
Selenium::WebDriver::Error::StaleElementReferenceError,
Selenium::WebDriver::Error::ElementNotInteractableError
<Handle Errors Here>
end
end
然后可以将该方法包装在可能导致问题的其他代码中
def SignIn
rescue_exceptions {
<Perform Actions Here>
}
end