Re: HELP: Need to continue the loop after the exception



On 2/19/08, mirth <mirthcyy@xxxxxxxxx> wrote:
In the watir unit test class I have:


def looptest
"do sth"
waiter = Waiter.new(300) # 5 min
waiter.wait_until {
if ($browser.frame("mainFrame").div(:text, /
Reports/).exists?)
true
end
rescue
"do sth"
end


def test_01
somearray.each{|obj|
looptest
}
end


The TimeOutException will happen when the browser doesn't return
Reports page in 5 minutes. When this exception happens, the browser
will keep running but test will exit the loop. But I need test_01 to
continue the loop even there's an exception and I want browser to
stop
when there's an exception.

Gosh. I'm stumped. I've been playing around with as close a facsimile
of your code environment as possible without actually using watir to
connect to your web app. I just can't replicate your behaviour. The
only thing that jumps out at me is that you're missing a closing } on
your wait_until block, but that should throw a syntax error if it was
more than a typo here. There's no reason the
Watir::Exception::TimeOutException shouldn't be caught, from what I
can tell. (and that is what's happening, from your description: the
exception isn't being caught, just as surely if you didn't have that
rescue in there)

TimeOutException ultimately descends from StandardError, so it should
be caught just fine, but one thing you can try is:

rescue Watir::Exception::TimeOutException

If all else fails, you can put the rescue within the iterator block:

begin
looptest
rescue Watir::Exception::TimeOutException
end

And that should catch the exception, no matter what. If there's more
to your code than what you've pasted (and since your code as currently
written would throw a syntax error, I have a hunch there is) then I'd
really drill down on it, because something is amiss.

Christopher

.



Relevant Pages