Thursday 16 January 2014

On Error Resume Next in QTP

Usually in keyword driven frameworks, we call the functions to perform specific operation like createOrder(), CancelOrder(). If error occurs in any of these functions, it is not important that we come back to main driver script and continue with next test case.

Code structure below demonstrates how we can do this in QTP.

'Code inside driver script.
On error resume next
'The advantage of the on error resume next is that we can continue to next statement if any error occurs in current statement.
Call createOrder()
If err.number <> 0 then
print err.description & err.source
End if
'*************************************************
'If error occurs at statement2, control of the script goes back to the caller. It does not execute any statment after statement2. This saves lot of time .

Function createOrder()
statement1......
statement2......
..........
more statements

End Function
**************************************************************************
Please note that if error occurs, control goes to next line of code and not the next block of code.
Example 1 -
on error resume next
a = 3/0
msgbox "hello"
msgbox "end"
'****************************************************************

Example 2 -
Consider below piece of code.
on error resume next
if (2/0) = 2 then
msgbox "true"
else
msgbox "false"
msgbox "end of code"
'************************************************************
Example 3 -
Consider below piece of code.
on error resume next
call myproc()
msgbox "end"
-------------------------------------------------------------------------------------
sub myproc()
if (2/0) = 2 then
msgbox "true"
else
msgbox "false"
end sub


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.