Translate

Exception Handling in QTP

Most of the times we do encounter a situation when an exception occurs, which is not actually a part of requirements. But, it is an unexpected behavior of the application. This is the reason it is called as exception & not error.
Some common examples are system went down, divide by 0 error etc.

These exceptions should be handled in the code, because if something unexpected happens then the script will not know what to do & it will fail.

Exception handling refers to anticipation & resolution of exceptions.

Some of the ways to handle exceptions is by using if..then..else statements, Switch Case statements.

Error Handling in QTP:

  • Synchronization: 
    • In QTP a synchronization point can inserted to instruct the script to pause the test until the condition specified in synchronization statement becomes true. 
    • An example where synchronization is required when you need to verify a value is present on a page & then based on that value take the next course of action. In this case if you don't wait for the page to load the script may not find the value & take a different course route altogether fetching incorrect results.
    • Synchronization can be achieved by using exist or waitproperty or both.
    • returnvalue = Object.Exist([Timeout])
    • returnvalue = Object.WaitProperty(PropertyName, PropertyValue, [Timeout])
  • Recovery Scenario:
    • A recovery scenario has 3 components:
      • Trigger: An exception that may occur & trigger the recovery scenario
      • Recovery: Instructions on how to handle recovery
      • Post Recovery: What next, after recovery is performed.
  • On Error statements:
    • On error statement can be used when you know that an error can occur at a point, but you don't want to notify.

No comments :

Post a Comment