gpt4 book ai didi

Ruby Selenium Net::ReadTimeout

转载 作者:行者123 更新时间:2023-12-02 10:57:31 25 4
gpt4 key购买 nike

我正在使用 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>'

最佳答案

准确地跟踪该错误来自代码中的位置,然后

begin
<driver execution code>
rescue Net::ReadTimeout
@driver.quit
end

这应该捕获错误并根据需要关闭 session 。

我所做的是编写一个单独的方法来处理错误

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

关于Ruby Selenium Net::ReadTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41503954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com