recovery scenario - on to next function when fails
I need to exit out a test case (or, as you will see below, an Inner Loop) and continue to the next one if QTP will not be able execute a line of code. I coded QTP to know it will not be able to execute the code on 2 coditions: the object does not exist or is disabled.
I'm creating all my test cases in 1 QTP file. Each test case is a function. Here is a typical function syntax:
for iOuterLoop = 1 to 3
for iInnerLoop = 1 to 1
At the top of the test script, my test cases are called:
What I want to do is exit the InnerLoop if any of the Functions (A,B,C) report a failure. These A,B,C functions have code that uses a method (SetUD) that replaced Set, Select (and so on) so if SetUD cannot do something, it reports a failure. I could have SetUD set a global variable when it fails, but right now the only solution I see is to use something like:
if bCannotEnter then
But I would have to use this code everywhere, after all my lines of code (or strategically selected code) in my test case function and my nested called functions.
I would like to use something like an "On Error" or recovery system (one that won't decrease perfomance) so that I only have to put a line of code at the start and end of the InnerLoop For statement.
Re: recovery scenario - on to next function when fails
Right, but that is what I wanted to avoid - having to update my existing code by adding a return (and if/else) for every call to the function.
So what i did instead is inside my SetUD method (replacing set, select, click...) is set a global variable to indicate the action could not be done. Then in the top of each function, I would have something like:
if gCouldNotSetUD <> True then exit function
At the start of the For loop I would reset it to:
gCouldNotSetUD = True
So this way I do not have to go through all my existing code and update it so that each function return a value and then use if/else every where.
there is a bit more to it than that, but I just wanted to post my solution in case anyone would be interested.