How to Debug a Test in UFT

A debugger is a powerful tool that enables you to run your test step by step. It’s a very essential skill and every automation tester must be acquainted with it. Using the debugger tool you can easily figure out where the issue lies in the code. You can also use the debugger tool at the time of the script development to check whether a piece of code is working fine especially when you are doing any mathematical calculation or you have to check whether the expected value is being returned from a function etc. In this article, I will explain in detail to understand how to debug a test in UFT.

The Process to Debug a Test in UFT

Prerequisites of Debugger Tool

If you are using UFT 12.02 or prior versions make sure Microsoft Script debugger is installed on your machine otherwise debugger tool in UFT/QTP won’t work. You can go to Control Panel and check whether it is installed.

Benefits of Using the Debugger Tool

  • You can watch the runtime values of variables
  • You can write your own expression at runtime check its output
  • Manipulating the values of variables at runtime

Different Ways to Debug a Test

  • Adding a Breakpoint
  • Running a Test by Pressing F11 or by selecting the Run>Step into the option.

Step-Into-UFT

  • Debug From Step by doing right-click at any step and select this 

Debug-from-Step_UFT

Adding BreakPoint

Inserting a breakpoint will stop the execution of the Test at the particular line and let you allow to execute each line step by step to figure out where is the issue in the script. You can add a breakpoint in the following ways.

  • Press F9 at the line
  • Go to “Run>Insert/Remove Breakpoint”
  • Do a left click at the line on the vertical bar just before the line number shown in the UFT Editor where you want to insert the breakpoint.
  • Do a left click in the left gray margin next to the line of code as shown below.

BreakPoint-UFT

After Inserting the breakpoint, the particular line will be highlighted as shown above.

Removing breakpoint

  • Press Ctrl+F9 at the line where there is a breakpoint
  • Go to “Run>Insert/Remove Breakpoint”
  • Again do a left click on the vertical bar just before line number where there is a breakpoint.

Debugging Methods

  • Step Into: Used to execute each and every step. Mostly used to steps into a Function/Action and executes line by line. It automatically pauses on each line after execution.
  • Step Over: Used to step over the step or function. The ‘Step Over‘ runs only the current step in the active document that means if you step over a function in your test, the whole function will be executed in one go and the script will pause at the next step of the function.
  • Step Out: After step into the function, you can use the Step Out option at any point to come out from the function. The run session is paused at the next line.

Working with Breakpoints

Write the following Code in the UFT Editor and add a breakpoint at the third line and run your Test.

UFT will Test will execute and stop at the breakpoint.
BreakPoint-UFT 2
Press the F10 key to move to the next step. We will notice that the execution arrow has moved to line 4.
BreakPoint-UFT-3
Again hit the F10 key. The message box will display 30.
BreakPoint-UFT-4

Add To Watch

Write the following code in the UFT Editor.

Add-Watch-UFT-7

Add the breakpoint at line number 3 and run the Test.

The execution will be paused in line 3.

BreakPoint-UFT-6

Press F11 to Step Into the function. The execution arrow will jump to line 7 to gon inside the function.BreakPoint-UFT-7

To know the runtime value of variable x, select it and do a right-click and select “Add to Watch” or select the variable and press Crtl+T.
Add-Watch-UFT
The variable would be added to the watch list and the Watch pane would become active. In the same fashion also add variable in the watch list.
Add-Watch-UFT-2
You can see the runtime value of both the x and y variable in the Watch pane. Press F10.The execution control will move to line 8 but the value of will still remain 10 and not 20 because line 8 has not yet executed.
Add-Watch-UFT-3
Now Press F10, line 8 will be executed and the value of y will be assigned to x. Hence the value of both and y would be 20.
Add-Watch-UFT-4
Press Shift+11 to Step out of the function. The execution pointer will come out of the function and the complete function would be executed and the execution pointer will now be pointing at line 4.
Add-Watch-UFT-5
Hit F10.Now the value of varX will be displayed as 20 as the value of varX and varY would have been swapped. Click on the OK button and hit F10. The value of varY must be displayed as 10.
Add-Watch-UFT-6

Add Expression

Add Expression gives you the flexibility to write a line of code at the runtime and check its output. Suppose you are debugging the aforementioned code and now the execution pointer is at line 5.By the time value of both varX and varY have been swapped which we can see in the Watch pane.
Add-Watch-UFT-7

Now we want to add 50 to varX at runtime and see what would be the value of varX after adding 50. We can do it by adding an expression in the Watch pane. Click on the + icon on the watch pane.
Add_Expression_UFT
Add New Watch window will be displayed. Write your expression here. I am writing varX+50. Press OK after writing the expression.
dd_Expression_UFT-477

The expression will be added to the watch list the output will be displayed.
Add-Watch-UFT-098

Updating the Value of a variable at Runtime

In the Watch pane, double the value column against a variable. It would become an editable field.
Update_var1 uft
Update the value of the variable. Here I am updating the value of varX from 20 to 40.Hit Enter after updating the value of the variable.
Add-Watch-UFT-0987
The value of varX would be updated to 40 and the value of expression varX+50 would also be updated and now it will be displaying 90 rather than 70.
*Note: If you are updating the value of a string variable, the value must be within double-quotes.

Recommended Posts

Leave a Reply