Handle Exception With Example, Handling Exception with Real world Scenarios Examples in QTP



Handle Exception With Example, Handling Exception with Real world Scenarios Examples in QTP

How can you handle exceptions in QTP ?

Exception handling in QTP is possible by the following methods:
  1. Recovery Scenarios
  2. Using the “On Error” Statement

Following need to define for Recovery Scenarios:
  1. Triggered Events
  2. Recovery Steps
  3. Post Recovery Test Run

On Script level you will be able to use the On Error Resume Next and On Error Go to with 0 Statement.

Recovery Scenarios: When running script get some unwanted or unexpected exceptions, So to recover such type of error and keep continue running from such unexpected error we required or need Recovery Scenarios.

Recovery Scenarios consist of the following:
  1. Trigger Event: This event will break up our session of executing script. For an example window that can show pop up on a screen but due to session end it could not possible.
  2. Recovery Operations: When trigger event break up the running session then this operations active the QTP to keep continue running. For an Example → Like Click on OK Button on Window Pop Up.
  3. Post Recovery Test Run Option: After the Guidelines how the QTP should behave and move further after the recovery operations have been executed, and now what point need or should keep continue. For an example → you have desire to restart the from the starting, or want to skip one step completely and want to continue with the next step in same step. So Recover scenarios will be saved in the recovery scenario files and have the .qrs extension. A recovery scenario file is a collection of logical scenarios and grouped according to our particular requirement.

Following Four events can be handle by the recovery scenario manager:

  1. Pop up window: Its used to handle unexpected pop ups
  2. Object State: Object related error handling during run time.
  3. Test Run Error : VN script statements error handling during run time.
  4. Application Crash: Crash Application handling during run time

We can understand it with following good example:

'Calling  the function to divide
call division
 
Function devision() 
on error will resume next
 
'divide by zero Exceptions
z=40/0 
 
' Report the  error occurred during executing script. 
Now You can see the number of errors and result summary description.
   If Err.number <> 0 then  
 
Reporter.ReportEvent micWarning,"Error Occured",
"Error number is  " &  err.number & " and description is : " &  err.description
 
 'disable the error handling 
   on error goto 0 
 
   End if
 
End function


Example: Like if you can assume that a definite event can happen at a particular point in our component or test, Then it is recommended to handle that even straight forward within our test by just adding the steps like if statement or optional step or “on error resume next”, instead of depending on scenarios of recovery. With the help of recovery scenario result may unusually slow performance of our test. Actually they designed to handle a more set of un - predictable events that can not be handled pro grammatically.




















Virtual Objects with Example in QTP
Cross Platform Testing


What is Object Spy in QTP Ordinal Identifiers Alone can Make an Object Unique









No comments:

Post a Comment

Popular Posts