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)
Solution. You can manually increase the wait time by hit-and-trial. If the problem persists for a longer period of time, there may be some other issue and you should continue onto the next solution. You can explicitly add wait by using JavaScript Executor.
You should try to increase the timeout to ensure that the objects are available to selenium to work. If you want to handle the error, better include this code in @BeforeTest or @BeforeSuite annotation which ensure the entire test suite will not run if this fails.
Defaults to 30 seconds (or 30,000 ms). When the object is used as input for the Set Timeouts command or as part of the timeouts capability when creating a new session, all fields are optional.
I have edited the env.rb since posting this and have updated that part of the question. This may not be the absolute fix but it is something I have noticed that to me- has fixed part of the problem.
I changed the timeouts in the env.rb from 300 to 20.
$driver.manage.timeouts.implicit_wait = 20
$driver.manage.timeouts.script_timeout = 20
$driver.manage.timeouts.page_load = 20
Upon doing that my test suite now executes much faster and instead of lengthy timeout errors I am getting real errors pertaining to my code (poor selector, wrong method etc).
Timeouts I used to get for simply navigating to a page have become:
Timed out waiting for page to load. (Selenium::WebDriver::Error::TimeOutError)
Which is appearing in less than 20 seconds but it may be due to the connection I have with the web page. I will be researching this error more in the near future.
If anyone tries this please let me know how it worked out for you (even if it didn't). I will keep updating this as I learn more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With