You know my method. It is founded upon the observation of trifles. ~ Sherlock Holmes

Why use the UFT Debugger?

A debugger is a tool to help you follow the logic of your test code as it runs. Debugging is attempting to figure out the cause of a problem in your test script, and then taking action to fix the problem.

Using the Debug command in UFT allows you to run your test line by line. This is helpful when developing your script when you’re having issues and you need to troubleshoot a problematic area in the script.

Microsoft Script Debugger Must be Installed

One “gotcha” you need to watch out for before using the UFT debug option is to make sure that you have the Microsoft Script Debugger installed. To double check, go to your Control Panel > Programs > Programs and Features and check to see if you have Microsoft Script Debugger listed:


If it hasn’t yet been installed, you can easily install it by going to Start >All Programs > HP Software >HP Unified Functional Testing> Tools > Additional Installation Requirements. Click Run.

The Seven Main Functions of the UFT Debugger

If it is not installed, the debug feature won’t be enabled.

The UFT Debugger has seven main areas:


In this post we’ll only cover the option that pertains to GUI testing.

Setting Breakpoints and Using the Breakpoints Pane

Breakpoints are cool because they allow you to stop at a particular line of code in your test script. This is a really handy feature if you’ve got a long script that is failing near the end of the test run and you need to pause the running to see why an issue is occurring. Let’s see a break point in action.

x = 2
y = 10
z = 22
total = x + y + z
msgbox total



Managing Breakpoints

The UFT breakpoint pane gives you a few options to manage your test scripts breakpoints.



This pane allows you to manage your breakpoints and give you the ability to:

Since breakpoints are not saved when you save your script, I’m not sure how helpful this pane actually is. But if you have a bunch of breakpoints, it might be handy. You can easily remove a breakpoint without using this pane — just click on the Red Ball.

Local Variables

Run the Debug script again and this time while it is paused, click on the UFT View>Debug > Local Variables option. You should now see a list of the current values contained in all your scripts variables:


This is great if your script is failing and you need to confirm whether or not the value you expect is actually showing up.

Stepping through your test code

While debugging your script you can navigate a few different ways. The UFT’s debugger has three kinds of navigation options, called “stepping”:

Let’s check each of them out.

msgbox addNumbers(50,20,10)

Function addNumbers
 (x,y,z)
addNumbers = x + y + z
End Function

Cool! Now let’s step into our code and see what happens:



This is helpful for debugging issues that may be occurring deep in one of your function libraries.

Call Stack

A call stack is a view of the nested sequence of functions that have led to a certain point in your test code. For example:

msgbox addnumbers(50,20,10)

Function addNumbers (
x,y,z)
total = x + y + z
subTotal = subtractNumbers(total,5,4)
    addNumbers = subTotal
End Function

Function subtractNumbers (x,y,z)
subtractNumbers = x + y + z
End Function


This can be helpful if you’re debugging and are paused inside a function and are not exactly sure how the path of execution got you to that point. It can help you get your bearings if you’re debugging long, nested functions. Just remember that the stack reads from the bottom up.

Console

The console can be a pretty powerful debugging tool. While you are debugging and UFT is paused on a line of code, you can perform multiple activities, like:

You can interact with the console by typing a line of code to be run in the context of your suspended run session.

Let go back to our original code example:

x = 2
y = 10
z = 22
total = x + y + z
msgbox total


Basically, what you’ve done is modified the variables values at run-time. The y variable now contains a value of 2 and the z variable now contains a value of 2. How cool is that?

Watch

The last GUI-based debugging option is the Watch pane. This allows you to set specific values to watch for selected variables and expressions in your test’s suspended run session. In a real world test script, you might have many variables but you may only be interested in 1 or 2 or them for your debugging purposes. This pane allows you to specify only the variables that you’d like to watch during the execution of your tests.

For example, say we only want to watch the Y value in our test example:


This is really useful, because if you’re debugging code that has a lot of variables you can define just the few that you are interested while debugging.

Debugging Help

Debugging can be tough. One book I’ve found really helpful for learning some great debugging principles is Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems. Check it out and become the Sherlock Homes of debugging test automation.