How to Use Call Stack in UFT to Trace Function Calls with Example

Call Stack in UFT is used to trace nested function calls. It is used while debugging a Test, where a stack trace in UFT helps automation testers to figure out where a problem lies in the code or how various subroutines and functions work together during execution.

call stack in uft

Example – Call Stack in UFT

Let’s consider it through the following example.

I have written the following three functions.
  • dispNumb
  • addNumb
  • multNumb

The dispNumb function is calling the addNumb function which in turn calls the multNumb function. Add a breakpoint inside the multNumb function as shown below and run the Test.

Call-Stack-Trace-UFT

When the script pauses, go to View>Debug> Call Stack.

call-Stack-Trace-UFT-02980

The Call Stack pane will be displayed.

call stack in uft example

The stack trace reads from the bottom up that is why the multNumb method would be displayed at top of the stack as it is the current function that is being called. By looking at the Call Stack you can easily figure out the flow of the execution path and how landed up inside a function.

Console in UFT

The Console pane in UFT is a very useful debugging tool. If you are debugging a Test and the script is paused at a breakpoint you can do the following things.

  • Getting information from the AUT(application under test)
  • Set or modify the value of variables
  • Performing an action on an object(The object must be in the object repository or use descriptive programming)
  • Use Print, Msgbox, and other test methods at runtime

Let’s try to understand the aforementioned things with the help of simple examples.

Console-UFT4Console-UFT-2

I have assigned some values to three different variables a,b and c. After that the I am setting the username to the Mercury demo application and clicking the Sign-In button. Here the catchy thing is that I am not setting any value to the password field. I will do that, later on, using descriptive programming.
I have set two break points in the script as shown below and running the Test.
Console-UFT-1
The script will pause at line 3. Now go to View>Debug> Console. The Console Pane will be displayed at the bottom of the UFT window with a command line as shown below highlighted with yellow color. You can type a valid command over here.
Console-UFT-2
In the command line, I am updating the value of b. Initially, the value of b is 30. I am reassigning a new value 50 to it by typing the command b=50. Press enter after entering the command.
Console-UFT-315
Hit F10 and enter command msgbox c in the command line and press the Enter key.
Console-UFT-335
A message box would be displayed with the value 75 as we have modified the value of variable b from 30 to 50 and c=a+b.
Console-UFT4
Now open the Mercury Tours Demo application by opening the URL http://newtours.demoaut.com and record and run settings keep the option “Record and run on any open browser”.Press F10.UFT will set the value for the username.
UserName
Now we will try to retrieve the value of the username from the application using the GetRoProperty method and display the same in the Output pane using the Print command.

Console-UFT-50

The output will be displayed in the Output pane.

Console-UFT6

Now the run pointer is at line 5 that is supposed to click the Sign-In button. But we haven’t entered the password. We will set the password in the password field using descriptive programming and writing this in the UFT command line field. Write the following code and press the Enter key.

Console-UFT7

It will set the password in the password field.

Password

At any point, you can clear the commands entered in the Console pane. Do a right-click and select the “Clear All” option.

Recommended Posts

Leave a Reply