Hi Sandeb,
I worked on a similar situation using Watir. We wanted to know when a page
took longer than 45 seconds to load. So I did some research and Ruby supports
a timeout block. The timeout block allows one to give an operation or set of
operations a specific time to complete, and if it doesn't complete within that
time it throws an exception. This exception can then be caught with a
begin...rescue block. I will show you here.
For example, let's say you want to load some page like Amazon.com, that might
be a little graphics intensive, or your page, like shown here:
require "watir"
# Start IE with a blank web page
ie = Watir::IE.start("about:blank")
# Try and browse to a page, timeout after 20 seconds, and retry if we timed out
while true # Loop continuously
begin # Start a begin...rescue block
timeout(20) do # Begin timeout
block
# Go to
pro.edgar-online.com website
ie.goto("http://pro.edgar-online.com/")
end # End timeout block
# Exit out of the while loop
because we got to the site within 20 seconds
break # Exit infinite while loop
rescue TimeoutError # Catch a timeout exception
redo # Retry the last operation
end # End begin...rescue block
end # End: while true
----------------------------------
So what happens here is first I have put everything into an infinite while loop
because that's the easiest way I can think of to make something "retry-able".
Next I put a timeout block around a goto action, and give it 20 seconds because
that's how long I think it should take to get there. If it takes longer then
there's some problem. After the timeout block I place a break statement to
break out of the infinite while loop in case I do load the page before 20
seconds. I put the timeout block in a begin...rescue(...end) block and catch a
TimeoutError which will be thrown if a timeout occurs, which will occur after
20 seconds if the webpage didn't load. I hope this is making some sense. If
not let me know.
If you have questions about what I've written here, let me know, thanks. This
is better than an assertion by the way and it keeps your script from crashing.
You have more control.
Nathan
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=5739&messageID=16054#16054
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general