如何在 Ruby 中为 Selenium 配置 read_timeout 和 open_timeout?
How to configure read_timeout and open_timeout for Selenium in Ruby?
我在通过 Watir 调用 goto()
时遇到此异常:
Net::ReadTimeout with #<TCPSocket:(closed)>
/usr/lib/ruby/2.6.0/net/protocol.rb:217:in `rbuf_fill'
/usr/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/usr/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
/usr/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
/usr/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/usr/lib/ruby/2.6.0/net/http.rb:1509:in `block in transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `catch'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1479:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
/var/lib/gems/2.6.0/gems/watir-6.16.5/lib/watir/navigation.rb:16:in `goto'
好像可以修改超时时间,但是我不明白怎么办。
它们已被使用 here,但我该如何配置它们?
可以参考Documentation Ruby-Bindings : Internal timeouts
From Documentation : Internal timeouts Internally, WebDriver uses
HTTP to communicate with a lot of the drivers (the JsonWireProtocol).
By default, Net::HTTP from Ruby's standard library is used, which has
a default timeout of 60 seconds. If you call e.g. Driver#get,
Driver#click on a page that takes more than 60 seconds to load, you'll
see a Timeout::Error raised from Net::HTTP. You can configure this
timeout (before launching a browser) by doing:
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :remote, http_client: client
在 Watir 中可能类似于
caps = Selenium::WebDriver::Remote::Capabilities.chrome
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 600
client.open_timeout = 600
driver = Watir::Browser.new :chrome, :desired_capabilities => caps,
:http_client => client
我在通过 Watir 调用 goto()
时遇到此异常:
Net::ReadTimeout with #<TCPSocket:(closed)>
/usr/lib/ruby/2.6.0/net/protocol.rb:217:in `rbuf_fill'
/usr/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/usr/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
/usr/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
/usr/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/usr/lib/ruby/2.6.0/net/http.rb:1509:in `block in transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `catch'
/usr/lib/ruby/2.6.0/net/http.rb:1506:in `transport_request'
/usr/lib/ruby/2.6.0/net/http.rb:1479:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:129:in `response_for'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/default.rb:82:in `request'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/http/common.rb:64:in `call'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/bridge.rb:167:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:567:in `execute'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/remote/w3c/bridge.rb:59:in `get'
/var/lib/gems/2.6.0/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/navigation.rb:32:in `to'
/var/lib/gems/2.6.0/gems/watir-6.16.5/lib/watir/navigation.rb:16:in `goto'
好像可以修改超时时间,但是我不明白怎么办。
它们已被使用 here,但我该如何配置它们?
可以参考Documentation Ruby-Bindings : Internal timeouts
From Documentation : Internal timeouts Internally, WebDriver uses HTTP to communicate with a lot of the drivers (the JsonWireProtocol). By default, Net::HTTP from Ruby's standard library is used, which has a default timeout of 60 seconds. If you call e.g. Driver#get, Driver#click on a page that takes more than 60 seconds to load, you'll see a Timeout::Error raised from Net::HTTP. You can configure this timeout (before launching a browser) by doing:
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120 # seconds
driver = Selenium::WebDriver.for :remote, http_client: client
在 Watir 中可能类似于
caps = Selenium::WebDriver::Remote::Capabilities.chrome
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 600
client.open_timeout = 600
driver = Watir::Browser.new :chrome, :desired_capabilities => caps,
:http_client => client