Saturday 16 August 2014

Error Handling Mechanism In QTP


Introduction



i)             Handling Unexpected Errors using Recovery Scenarios
                    While executing QTP scripts, we may face unexpected errors which might stop the execution and give undesirable results. To handle these kind of situations, QuickTest uses recovery scenarios that performs the operation to recover and continue the execution


ii)            Handling VB Script Run Time error Using VB Script Statements
                 Run errors occur in VB code while execution due to Object required errors , Out of memory , Type mismatch, etc., In these conditions, It can cause an error message pop up to be displayed and stop the execution. Hence we are using “On Error Resume Next” statement which suppresses the error popup and proceeds to the next step instead of stopping the entire execution.
“Err object” is used to display the information about run time errors


iii)           Error Handling with “QTP Test Settings”
                     QTP displays pop up window by default if any error occurs. This is due to the default selection in QTP Test Settings. We can select different options other than pop up window to instruct QTP how to
Respond when an error occurs


iv)           Disabling all IE Pop ups using Silent object method
                       We can disable all the pop ups displaying in Internet explorer by using Silent object. Hence whatever popups come up in the browser, it will close those pop ups

 


 

 



Handling Unexpected Events using Recovery Scenarios

Text Box: Recovery Scenario Manager 


           

To handle unexpected errors, QTP has Recovery Scenario Manager to create Recovery scenarios. Recovery scenarios files are saved in .qrs format

Example:
Let’s consider an example how to handle Object State Triggers.
Sometimes we may get below certificate error page while launching an application or while navigating to some pages. In this case, we have to click either close the page or continue to the site

While doing web testing if one doesn’t know when this error page will get displayed exactly, then it is better to go for recovery scenarios

a)    Select the trigger type Event as Object State


b)    Select an object in the application on which the action needs to be performed

c)    Select a Recovery Option


d)    Define new function in library file or select a function from library file
        The function defined here is
        Function RecoveryFunction1(Object)
Browser("name:=Certificate Error:.*").Page("title:=Certificate                        Error:.*").Link("text:=Continue to this website.*","html tag:=A").Click
       End Function
e)    Select Post Recovery Option

     
           
f)    Save this recovery  scenario


g)    Associate recovery scenario with the test script



h)       Associate the corresponding library file with the test script

i)     Test result after execution




Advantages

1)    More than One recovery scenarios can be associated with the test script
2)    Reduces the number of lines of code ( for ex., If a pop up window comes in most of the application pages, we can use recovery scenario instead of writing a code in every function to handle the popup)
3)    We can prioritize and enable/disable the recovery scenarios
4)    Effective for handling unexpected errors

Disadvantages

1)    For few scenarios, it reduces the speed of execution( For ex : , In Settings , if we select the option “On every step” , then QTP would search for the trigger event on every step which slow down the performance)
2)    Recovery scenarios can’t handle VB Script run time errors

Handling VB Script Run Errors in QTP


   In QTP, Run error occurs while execution due to following type of errors                                                                                                                         
           E.g., Division by Zero
                    Named argument not found                                                                            
                   Object Required
                   Error in Loading DLL 
These errors make QTP stop the execution. Hence we are using “On error Resume next” to          proceed to the next step even though an error occurs in the previous step
Consider this example,

                   When the above code is being executed, the below error message is displayed due to improper object declaration and it needs manual intervention to proceed to the next step
             

 Solution:     
                On Error Resume next statement is added in the same above code, then this error pop up will not be displayed which results in continuous execution
                On Error Goto 0 statement is used to disable the error handling operation of On Error Resume Next i.e., If any error occurs in line number 10 , then error pop up window will be displayed


In the above results , there is no information about error that occurred. Hence we can use Err object to capture the error details
 When an error occurs, Err object will be having the information about the error like error number, error description,source etc., as below


Advantages

                On Error Resume next helps QTP to continue the execution even though if any run time error occurs in the middle

Disadvantages

                It is inappropriate to use in case where a function uses the output of a previous function as input. For ex., Function A should return number of users as 10 which can be used as input to the following Function B .If any error occurs in Function A, then it will not display error message due to On Error resume next but return some unexpected value. If function B uses this value then all the following steps will fail.
             Here the recommendation is to use ExitTest() statement in ‘Else’ Part of the function A. So that whenever a test step fails in function A ,QTP will stop the execution instead of executing all the remaining steps with unexpected value. It is easy to debug as well in the result file.
Text Box: Note : When you execute a script from Quality Center, Error Popups will be closed automatically i.e., these error popups do not stop the execution
 





Error Handling with “QTP Test Settings”


Go to QTPà Test Settings à Run
There are 4 options displayed in web list which instructs QTP how to respond when an error occurs


pop up message box : This is the default option when an error occurs. Here user has to click on the button in that error message box to proceed or end the session
proceed to next action iteration : QTP continues to the next action iteration when an error occurs
stop run : QTP stops the entire execution if an error occurs
proceed to next step :QTP proceeds to the next step even if an error occurred in the previous step
Text Box: Note: If an error occurs, QTP first calls Recovery scenarios to handle those errors and if associated recovery scenarios do not work fine, then it will perform the action according to the option selected above.
 



Disabling all IE Pop ups using Silent object method


We can disable all the pop ups displayed in IE Browser by using silent method as below
Browser(“xyz”).Object.Silent = True
Hence whenever the above statement is executed, QTP closes the popup on the specified browser

Advantages

We can easily close the popups in just one simple statement without creating any recovery scenarios or making any functional call

Disadvantages

It will close all the pop ups which are part of test case also
It will always click on default action on the dialog window. If No is the default option in a window, then it will click No option
This silent method is supported only by IE browser

Conclusion

Each Error handling technique described here has its own advantages and limitations. Hence one has to choose based on the test requirements



0 comments :

Post a Comment