/usr/lib/ruby/1.9.1/net/protocol.rb:146:在`rbuf_fill中救援':超时::错误(超时::错误)

时间:2012-10-16 19:24:07

标签: ruby selenium capybara

我正在使用Capybara(Selenium驱动程序)访问网站上的某些页面。我只需点击数组中的每个项目,然后单击后退按钮。它很好,但每次经过一些迭代后它就会破坏。 这是代码:

all(:xpath, '//table[@class="griglia_bordata"]//tr[td]/td/a[1]').each do |a|
  a_js_functions << a[:href]
end
a_js_functions.each do |js_for_model|
  puts js_for_model
  page.execute_script js_for_model
  find(:xpath, "//a[text()='Check availability']").click
  puts find(".testo_grande_blu_B").text
  puts "--------------------------------------------"
  find(:xpath, "//a[text()='Back']").click
end

我有输出:

  

javascript:selectModel(&#39; 130254&#39;)样式:RB2132   -------------------------------------------- javascript:selectModel(&# 39; 309257&#39;)风格:RB2140   -------------------------------------------- javascript:selectModel(&# 39; 68238&#39;)风格:RB3016   -------------------------------------------- javascript:selectModel(&# 39; 68248&#39;)风格:RB3025   -------------------------------------------- javascript:selectModel(&# 39; 68293&#39;)风格:RB3026   -------------------------------------------- javascript:selectModel(&# 39; 68320&#39;)风格:RB3044   -------------------------------------------- javascript:selectModel(&# 39; 68460&#39)   /usr/lib/ruby/1.9.1/net/protocol.rb:146:in rescue in rbuf_fill': Timeout::Error (Timeout::Error) from /usr/lib/ruby/1.9.1/net/protocol.rb:140:in rbuf_fill&#39;从   /usr/lib/ruby/1.9.1/net/protocol.rb:122:in readuntil' from /usr/lib/ruby/1.9.1/net/protocol.rb:132:in readline&#39;从   /usr/lib/ruby/1.9.1/net/http.rb:2562:in read_status_line' from /usr/lib/ruby/1.9.1/net/http.rb:2551:in read_new&#39;从   /usr/lib/ruby/1.9.1/net/http.rb:1319:in block in transport_request' from /usr/lib/ruby/1.9.1/net/http.rb:1316:in赶上&#39;从   /usr/lib/ruby/1.9.1/net/http.rb:1316:in transport_request' from /usr/lib/ruby/1.9.1/net/http.rb:1293:in请求&#39;从   /usr/lib/ruby/1.9.1/net/http.rb:1286:in block in request' from /usr/lib/ruby/1.9.1/net/http.rb:745:in开始&#39;从   /usr/lib/ruby/1.9.1/net/http.rb:1284:in request' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in response_for&#39;从   /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:in   request' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in 呼叫&#39;从   /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in   raw_execute' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in 执行&#39;从   /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:554:in   find_elements_by' from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/search_context.rb:62:in find_elements&#39;从   /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/selenium/driver.rb:52:in   find' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:158:in find_in_base&#39;从   /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:137:in   block in first' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:136:in 各&#39;从   /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:136:in   first' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in 阻止查找&#39;从   /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/base.rb:46:in   wait_until' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in 找到&#39;来自(eval):2:在find' from /var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in 中找到&#39;从   /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:39:in block in scrape' from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:36:in每个&#39;     来自/home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:36:in   scrape' from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:12:in去&#39;     来自/home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:48:in   `&#39;

2 个答案:

答案 0 :(得分:6)

我之前看到过类似的痕迹和2个潜在原因:

1)像FakeWeb和WebMock这样的宝石修改了ruby的http。尝试删除那些您可能用来模拟/阻止Web请求的宝石和任何类似的宝石。

2)我在一个真正负载的系统中看到了一个案例,这个超时会有些随机发生。真的,这里的问题不是测试,而是系统及其上运行的内容。可以更改http库使用的超时并继续测试。

更新了Capybara :(来自http://selenium.googlecode.com/svn/wiki/RubyBindings.wiki

Capybara.register_driver :selenium_extended_http_timeout do |app|
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.timeout = 240
    Capybara::Selenium::Driver.new(app, 
                               :browser => :firefox, 
                               :http_client => client, 
                               :resynchronization_timeout => 60,
                               :resynchronize => true)                                                                   
end
Capybara.javascript_driver = :selenium_extended_http_timeout

您很可能不需要重新同步的东西。

在这两种情况下,这都与硒如何进行内部沟通有关。 JsonWireProtocol。

答案 1 :(得分:0)

我在Fakeweb&amp; amp;录像机但升级到selenium-webdriver(2.27.0)后,超时消失了