10

I have been getting a Timeout error ever since I started developing my tests. At first I thought it was related to the efficiency of my xpaths but after seeing the test pass quickly numerous times I don't think it is related to the selectors. The error randomly occurs and often when it does it occurs multiple times within a feature. I need to fix or at least understand what this problem is.

An example of a step definition:

When /^I navigate to "(.*)"$/ do |webpage|
navigate_to(webpage)
end

This is the error I get:

 Timeout::Error (Timeout::Error)
      /usr/lib/ruby/1.9.1/net/protocol.rb:146:in `rescue in rbuf_fill'
      /usr/lib/ruby/1.9.1/net/protocol.rb:140:in `rbuf_fill'
      /usr/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
      /usr/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
      /usr/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
      /usr/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
      /usr/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
      /usr/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
      /usr/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
      /usr/lib/ruby/1.9.1/net/http.rb:1293:in `request'
      /usr/lib/ruby/1.9.1/net/http.rb:1286:in `block in request'
      /usr/lib/ruby/1.9.1/net/http.rb:745:in `start'
      /usr/lib/ruby/1.9.1/net/http.rb:1284:in `request'
      ./features/support/env.rb:88:in `block in get_page_url'

The env.rb :

require 'selenium-webdriver'
require 'rubygems'
require 'nokogiri'
require 'rspec'
require 'rspec/expectations'
require 'httpclient'
require 'fileutils.rb'
require 'pathname'

$driver = Selenium::WebDriver.for :ie
#accept_next_alert = true
$driver.manage.timeouts.implicit_wait = 300
$driver.manage.timeouts.script_timeout = 300
$driver.manage.timeouts.page_load = 300
#verification_errors = []

AfterStep do
 sleep 5
end

at_exit do
    $driver.close
end

I have gone through numerous questions about this very same topic and none seem to have an answer that works, if an answer at all.

Similar issue. I have tried the solutions provided here but my error still persist https://www.ruby-forum.com/topic/4414675

I have tried adding explicit waits as such: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

I need to get this issue sorted out so please ask questions if I wasn't clear on anything.

Here is a list of installed gems:

archive-tar-minitar (0.5.2)
bigdecimal (1.1.0)
builder (3.2.0)
bundler (1.3.5)
childprocess (0.3.9)
columnize (0.3.6)
commonwatir (4.0.0)
cucumber (1.2.3)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.2)
diff-lcs (1.2.1)
ffi (1.5.0, 1.0.9)
gherkin (2.11.6)
hoe (3.6.2)
httpclient (2.3.2)
io-console (0.3)
json (1.7.7)
linecache19 (0.5.12)
mime-types (1.23)
mini_magick (3.6.0)
mini_portile (0.5.0)
minitest (2.12.1, 2.5.1)
multi_json (1.7.1)
nokogiri (1.5.9)
rack (1.5.2)
rack-test (0.6.2)
rake (10.0.3, 0.9.6)
rautomation (0.9.2)
rb-readline (0.5.0)
rdoc (3.12.1)
rspec (2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
rspec-mocks (2.13.0)
ruby-debug-base19 (0.11.25)
ruby-debug19 (0.11.6)
ruby_core_source (0.1.5)
rubygems-update (2.0.3)
rubyzip (0.9.9)
s4t-utils (1.0.4)
selenium-webdriver (2.33.0, 2.31.0)
subexec (0.2.3)
user-choices (1.1.6.1)
watir (4.0.2)
watir-classic (3.7.0)
watir-webdriver (0.6.2)
websocket (1.0.7)
win32-api (1.4.8)
win32-process (0.7.2)
win32screenshot (1.0.8)
windows-api (0.4.2)
windows-pr (1.2.2)
xml-simple (1.1.2)
xpath (2.0.0)
4

7 回答 7

2

自发布此消息以来,我已经编辑了 env.rb 并更新了问题的那一部分。这可能不是绝对的解决方法,但我注意到对我来说已经解决了部分问题。

我将 env.rb 中的超时时间从 300 更改为 20。

$driver.manage.timeouts.implicit_wait = 20
$driver.manage.timeouts.script_timeout = 20
$driver.manage.timeouts.page_load = 20

这样做后,我的测试套件现在执行得更快,而不是冗长的超时错误,我得到了与我的代码有关的真正错误(糟糕的选择器,错误的方法等)。

我过去常常因为简单地导航到一个页面而得到的超时现在变成了:

 Timed out waiting for page to load. (Selenium::WebDriver::Error::TimeOutError)

不到 20 秒就出现了,但这可能是由于我与网页的连接。我将在不久的将来更多地研究这个错误。

如果有人尝试这个,请告诉我它是如何为你工作的(即使它没有)。随着我了解更多,我将继续更新此内容。

于 2013-08-01T18:48:36.937 回答
0

论坛上有关于这个问题的Ruby讨论。

对于 2013 年 7 月 19 日,似乎没有修复它,但有一个建议是延长失败前的时间:

 driver.manage.timeouts.page_load = 300 # 5 minutes
于 2013-07-24T06:12:56.923 回答
0

我在使用 watir-webdriver 时遇到了这个错误,就我而言,我试图访问:

@browser.goto "localhost:3000/#/login"

当我应该访问时:

@browser.goto "http://localhost:3000/#/login"

奇怪的是,我调用此方法的第一个场景有效,但是在我的第二个场景中尝试导航相同的 URL 时,我收到了与您的类似的堆栈跟踪

于 2013-12-09T15:51:54.207 回答
0

尝试在您的 Rails 应用程序中删除位于 tmp/cache 中的缓存文件夹,并在应用程序的根目录下运行“rake assets:clean:all”

于 2013-07-28T04:02:12.947 回答
0

与其他浏览器相比,Internet Explorer 的 xpath 问题更多。我曾经使用 webdriver 和 java 遇到过这个问题。您是否尝试过使用 css 选择器实例化 Selector 并查看这是否有助于浏览器定位元素?

于 2013-07-26T15:03:14.667 回答
0

我现在使用硒进行刮擦而不是测试,我正在处理这样的事情:

browser_name = :chrome
http_client = Selenium::WebDriver::Remote::Http::Default.new(open_timeout: 5.minutes, read_timeout: 5.minutes)
@browser = Watir::Browser.new browser_name, http_client: http_client
于 2019-11-22T12:05:18.137 回答
0

--headless在我的情况下,禁用选项是有效的。

于 2020-02-19T23:14:38.633 回答