Skip to main content

Error Handling and Recovery Scenarios in QTP - Part-2

VBScript Error Handlers
In Part-1 we have discussed about Recovery Scenario and now we know that Recovery Scenarios are useful to continue the script execution whenever an error/exception/unexpected event interrupts the script execution. But Recovery Scenarios will not handle VBScript Errors. It can only handle QTP Errors.
What is an error in VBScript?
When working with VBScript you get two types of errors.
  1. Syntax Errors
  2. Runtime Errors
Syntax Errors:
Syntax error is a grammatical mistake. In that case VBScript compiler doesn’t understand your statement and throws an error. It can be found in compilation stage before the script has begun to be executed. Ex: calling a sub with parenthesis “(“.
You can find the list of syntax errors in QTP Help File (Press F1 to get) –> VBScript Reference –> VBScript –> VBScript Language Reference –> Errors (VBScript) –> VBScript Syntax Errors
Run Time Errors:
Runtime Errors shows when VBScript attempts an action that the system cannot execute. Run-time errors occur in script execution time when variable expressions are being evaluated, and memory is being dynamic allocated. Ex: When calling a function which is not there/loaded, When assigning values to an array more than allocated size.
You can find the list of syntax errors in QTP Help File (Press F1 to get) –> VBScript Reference –> VBScript –> VBScript Language Reference –> Errors (VBScript) –> VBScript Runtime Errors
How to handle VBScript Errors?
You cannot skip from syntax errors. You must fix them in order to start execution. There is no specific recovery mechanism for VBScript runtime errors. But you can suppress them.
On Error Resume Next: This statement will simply suppress the errors and executes entire script. Suppressing the error means when error occur VBScript shows popup error message, pauses execution and waits for user action. When using this statement, the error popup will not be displayed on failure and goes to the next statement for execution.
On Error Go to 0: This statement is used to disable “On Error Resume Next”.
In VBScript there is no facility to call a statement/function on error. But you can use err object to perform condition based error handling. On Error Resume Next, Go to 0 and Err objects will work for VBScript as well as for QTP Objects.
Err Object: This object captures the information about runtime errors. Using this you can always get the last error details. To access error details you can use err.number or err.description statements. We can clear and raise the runtime errors using this object.
Condition Based Error Handling
You can use this when not using recovery scenarios.
  1. 'Clear the error         
  2. err.clear         
  3.         
  4. 'Execute a statement         
  5. Browser("Google").Page("Google").WebButton("SignIn").click         
  6.         
  7. 'Verify error. If error exist, err.number contains a value. Otherwise the value is empty.         
  8. if err.number<>"" then         
  9.     Reporter.Reportevent micpass,"Button Click""Clicked on Sign In Button"         
  10. Else        
  11.     'Call a recovery function here if needed         
  12.     'Send error details to result         
  13.     Reporter.Reportevent micfail,"Button Click""Clicked on Sign In Button Failed"&vbnewline&"Error Details: "&err.description         
  14. End If       
  15. 'Clear the error     
  16. err.clear     
  17.     
  18. 'Execute a statement     
  19. Browser("Google").Page("Google").WebButton("SignIn").click     
  20.     
  21. 'Verify error. If error exist, err.number contains a value. Otherwise the value is empty.     
  22. if err.number<>"" then     
  23.     Reporter.Reportevent micpass,"Button Click""Clicked on Sign In Button"     
  24. Else     
  25.     'Call a recovery function here if needed     
  26.     'Send error details to result     
  27.     Reporter.Reportevent micfail,"Button Click""Clicked on Sign In Button Failed"&vbnewline&"Error Details: "&err.description     
  28.          
  29.     'Clear the error from cache     
  30.     err.clear     
  31. End If    
  32. 'Clear the error      
  33. err.clear      
  34.      
  35. 'Execute a statement      
  36. Browser("Google").Page("Google").WebButton("SignIn").click      
  37.      
  38. 'Verify error. If error exist, err.number contains a value. Otherwise the value is empty.      
  39. if err.number<>"" then      
  40.     'Call a recovery function here if needed      
  41.     'Send error details to result      
  42.     Reporter.Reportevent micfail,"Button Click""Clicked on Sign In Button Failed"&vbnewline&"Error Details: "&err.description     
  43.   
  44. Else     
  45.      Reporter.Reportevent micpass,"Button Click""Clicked on Sign In Button"      
  46. End If  
Why VBScript Errors cannot be handled by Recovery Scenario Manager?
QTP is having a large set of Objects, Methods, Properties, statements and Keywords that are not available in VBScript. But to access QTP objects/methods/properties/statements/keywords we must use the standards of VBScript. QTP Recovery Scenario Manager is developed to handle the issues that are occurred when working with QTP Test objects. So Recovery Scenario Manager works only with the errors that are related Test Objects and It cannot handle any other errors.
QTP activate Recovery Scenarios only on below errors. Whether it is Popup/Object State/TestRun Error/Application crash QTP gets any of the below error and activates the Recovery Scenario Mechanism.
  • Object Not Found
  • Item in list or menu is not unique
  • Item in list or menu not found
  • More than one object responds to the physical description
  • Object is disabled
  • Object not found
  • Object not visible
When to use Recovery Scenario Manager and VBScript Error Handlers?

Recovery Scenario Manager useful to handle the test object related errors and VBScript error handlers useful to handle VBScript runtime errors. We must use both in order to complete the execution.

Comments

Popular posts from this blog

JMeter Exceeded Maximum Number of Redirects Error Solution

While running performance test, JMeter allows maximum 5 redirects by default. However, if your system demands more than 5 redirects, it may result in JMeter exceeded maximum number of redirects error. In this post, we have listed down steps to overcome this error. Actual error in JMeter: Response code: “Non HTTP response code: java.io.IOException” Response message: “Non HTTP response message: Exceeded maximum number of redirects: 5” This error is noticed because  JMeter  allows maximum 5 redirects by default and your system may be using more than 5 redirects. You need to increase this count to more than 5 in jmeter.properties file. Follow below steps to achieve this. Navigate to /bin directory of your JMeter installation. Locate jmeter.properties file and open it in any editor. Search for “httpsampler.max_redirects” property in opened file. Uncomment the above property by removing # before it. Change to value to more than 5 Eg. 20. Save the file and restart JMeter. If

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We can do this b

A Tutorial to Send Email using JMeter

Sending email is a mundane activity in any professional’s life. It’s a common medium for communication nowadays. Therefore performance testing of email server is not only important but necessary for an organization. JMeter can be helpful to perform load testing in such scenarios. In this tutorial, we will see how JMeter can be used to send email. We will use SMTP Sampler of JMeter to send an email. JavaMail API is needed to enable email functionality in JMeter. Download it from  here  and paste the jar in JMeter’s lib folder. Now, perform below steps to configure SMTP Sampler. Add a new Thread Group under Test Plan. Right click on Thread Group and select Add–>Sampler–>SMTP Sampler. We need to populate SMTP server’s details in this sampler. We will use GMail for sending an email. For this, enter these values in SMTP Sampler fields. Server: smtp.googlemail.com, Port: 587. Provide values in Email Address From and To fields of Mail Settings section to specify sender and reci