I am using Capybara (Selenium driver) for visiting some pages on the site. I just click on every item in the array and click back button. It goes fine but every time after some number of iterations it brokes.
Here is code:
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
I’ve got output:
javascript:selectModel(‘130254’) Style: RB2132
——————————————– javascript:selectModel(‘309257’) Style: RB2140
——————————————– javascript:selectModel(‘68238’) Style: RB3016
——————————————– javascript:selectModel(‘68248’) Style: RB3025
——————————————– javascript:selectModel(‘68293’) Style: RB3026
——————————————– javascript:selectModel(‘68320’) Style: RB3044
——————————————– javascript:selectModel(‘68460’)
/usr/lib/ruby/1.9.1/net/protocol.rb:146:inrescue in rbuf_fill':rbuf_fill’ from
Timeout::Error (Timeout::Error) from
/usr/lib/ruby/1.9.1/net/protocol.rb:140:in
/usr/lib/ruby/1.9.1/net/protocol.rb:122:inreaduntil' fromreadline’ from
/usr/lib/ruby/1.9.1/net/protocol.rb:132:in
/usr/lib/ruby/1.9.1/net/http.rb:2562:inread_status_line' fromread_new’ from
/usr/lib/ruby/1.9.1/net/http.rb:2551:in
/usr/lib/ruby/1.9.1/net/http.rb:1319:inblock in transport_request'catch’ from
from /usr/lib/ruby/1.9.1/net/http.rb:1316:in
/usr/lib/ruby/1.9.1/net/http.rb:1316:intransport_request' fromrequest’ from
/usr/lib/ruby/1.9.1/net/http.rb:1293:in
/usr/lib/ruby/1.9.1/net/http.rb:1286:inblock in request' fromstart’ from
/usr/lib/ruby/1.9.1/net/http.rb:745:in
/usr/lib/ruby/1.9.1/net/http.rb:1284:inrequest' fromresponse_for’ from
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:82:in
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/default.rb:38:in
request' fromcall’ from
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/http/common.rb:40:in
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:598:in
raw_execute' fromexecute’ from
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:576:in
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/remote/bridge.rb:554:in
find_elements_by' fromfind_elements’ from
/var/lib/gems/1.9.1/gems/selenium-webdriver-2.25.0/lib/selenium/webdriver/common/search_context.rb:62:in
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/selenium/driver.rb:52:in
find' fromfind_in_base’ from
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:158:in
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:137:in
block in first' fromeach’ from
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:136:in
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:136:in
first' fromblock in find’ from
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/base.rb:46:in
wait_until' fromfind’ from (eval):2:in
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/node/finders.rb:27:in
find' fromfind’ from
/var/lib/gems/1.9.1/gems/capybara-1.1.2/lib/capybara/dsl.rb:161:in
/home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:39:inblock ineach’
scrape' from
/home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:36:in
from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:36:in
scrape' fromgo’
/home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:12:in
from /home/biske/workspace/ScrapingGlasses/lib/luxottica.rb:48:in
`’
I’ve seen a similar trace before and 2 potential causes for it:
1) gems like FakeWeb and WebMock modify ruby’s http. Try removing those gems and any similar ones you may be using to mock/block web requests.
2) I’ve seen a case in a really loaded down system where this timeout would occur somewhat randomly. Really the issue here wasn’t the test but the system and what was running on it. It’s possible to change the timeout used by the http library and continue testing.
Updated for Capybara: (from http://selenium.googlecode.com/svn/wiki/RubyBindings.wiki)
There’s a good chance you don’t need the resynchronization stuff.
In both cases this is related to how selenium does some of its internal communications. The JsonWireProtocol.