Reading:  

Quick Test Professional - The starters Guide


Debugging and Error Handling

Debugging is the process of finding and also fixing bugs in program code, to make the product more robust. 

The Debug options are available in run menu as shown below:

Debug options QTP

 

The Methods of Debugging are:

 

Step Into: This is useful to debug in the called function of script and run each step as line by line in the function. While navigation into a function definition from the function called in script. We can use Debug>Step Into/Click F11 or click on Step into button.

Step Over: It does not debug into a function called within script, but executes the function as a step and moves to next step in the Test. Step over does debugging line by line in the script. We can use Step Over using F10 Key or Debug>Step Over or icon for Step Over in the QTP IDE.

Step Out: Suppose we have step into a function as explained in Step Into, and needs to come out of the function, we use Step out Option. We can use Step Over using shift + F11 Key or Debug>Step Out or icon for Step Out in the QTP IDE.

 

Break Point Options are:

Options in Break Point can be accessed by Navigating 'Run' Menu.

ShortCut

Description

F9

To Add/Remove Breakpoint

Ctrl+F9

To Enable/Disable Breakpoint

Ctrl+Shift+F9

To Clear All Breakpoint

Use Only Menu

To Enable/Disable All Breakpoints

 

Upon Inserting the Break point the line will be as shown below:

 

Debugging Pane:

The panes in the debugging window:

  • Output – Tab which displays the Output of the Print Statements.
  • Watch - Tab which displays the output of the Given Expression in Boolean value.
  • Local Variables –Tab which displays the Local Variables Output.

Example:

The Watch Pane shows the output as shown:

 

The Local Variables Pane shows the values of local variables as shown:

 

Local Variables Pane QTP

 

Error handling

Error handling is anticipating an error at any point of the script then detecting that error and handling the error.

Classification of errors:

  1. Syntax errors
  2. Logical errors
  3. Run time errors

 

Syntax errors: Is part of the code which does not confirm with the grammar of the programming language. These errors occur at the time of compilation of code and can be easily find before the execution of the code.

Go to View select Errors, If the window is NOT displayed the error.

 

Logical error: A logical error is a part of code to produce unexpected failures; it may be in some functions or in some manipulations, it is because of some misconception or wrong understanding requirement. Logical error does not halt or stop the execution but makes it to produce incorrect results.

Run time errors: are basically those errors which occur during the at run time. The reason for these errors is, if script tries to do a specific action but due to some reason that is impossible to perform. 

Run Time Errors examples are,

  1. Object NOT.
  2. File NOT.
  3. Array Index out of bounds while accessing array elements.
  4. Dividing a number by Zero.

Handling Run-Time Errors:

Ways to handle errors:

  • Using Test Settings
  • Using On Error Statement
  • Using Err Object
  • Using Exit Statement
  • Recovery Scenarios
  • Reporter Object

Using Test Settings:

Go to 'File' select 'Setting' select 'Run Tab', select the specified settings and click "OK".

On Error Statement:

By using this tester can handle the run time error to avoid not user friendly error message.

  • On Error Resume Next: This statement allows to handle error in the script. If script has error in it "On error Resume Next" ignores it and continues with next line of script.
  • On error go to 0: This statement disables error handling which is enabled it by using On Error resume Next.

Using Err Object:

This is an inbuilt object which is used to captures the run-time error number and description of error; it is helpful for debug the error.

  • Number: Returns a group of numeric value specifying an error. If the Err.Number value is equal to 0 then No error had occurred.
  • Description: Returns a group of in-detail description about an error.
  • Clear: This is used to resets the Err object and clears all the old values associated with it.

Example:

'Call  the function to Add two Numbers
Call Addition(num1,num2)

Function division() 
on error resume next
 
'divide by zero
z=9/0 
 
If Err.number <> 0 then  
 
Reporter.ReportEvent micWarning,"Error!!!","Error number is  " &  err.number & " and description is : " &  err.description

  'disables error handling
   On Error Goto 0

End function
 

 

Using Exit Statement:

Exit Statement types are:

  • ExitTest: This statement used to Exits test completely.
  • ExitTestIteration: Exits test iteration and move to next test iteration (if exists).here test is global.
  • ExitAction: This statement is Exits the current task.
  • ExitActionIteration: Exits action iteration and proceeds to next action iteration (if exists and is enabled in Action Call Properties).here action is local.

Recovery Scenarios:

This is useful to continue the execution when it is stopped by any unexpected error. The occurred error, information will be collected by QTP Recovery process and a predefine recovery scenario will be executed to overcome interruption of error and to continue the execution.

Reporter Object:

This is mainly used for sending information to the test results.

With the help of this object you can:

  • The test results Report status are: pass, warning ,fail
  • Reporting of step(s) can be Enable/Disable.
  • Retrieve the folder path of current test’s results are stored.
  • Retrieve the current point of the run session run status.

Example:

'Syntax: Reporter.ReportEventEventStatus, ReportStepName, Details, [ImageFilePath]

'Example
Reporter.ReportEvent micFail, "Login", "Unable to Sigin." 
 

 

Description

In this tutorial, we will get to know Quick test professional. At the time of writting QTP is at version 12.2. This tutorial is subdivided into multiple parts as shown below

  • What is QTP
  • Automating tests
  • Environment
  • Recording and Playback
  • Object Repository
  • Actions
  • Data Table
  • Checkpoints in QTP
  • Synchronization
  • Smart Identification
  • Debugging and Error handling
  • Recovery Scenarios
  • Environment Variables
  • Library Files
  • Test Results
  • GUI Objects
  • Virtual Objects
  • Accessing Databases
  • Working with XML
  • Descriptive Programming
  • Automation Object Model
  • A work on Frameworks

Leave your feedback for us, Feedback help us improve our tutorials.

 



Prerequisites

Some knowledge on Windows OS and VB Script is recommended

Audience

Students who wish to learn QTP

Learning Objectives

Learn QTP

Author: Subject Coach
Added on: 16th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!