How to Debug a UFT script in VBScript Debugger?

Spread the love
  • 20
  • 28
  • 12
  • 23

How to Debug a UFT script in VBScript Debugger?
How to Debug a UFT script in VBScript Debugger?

How to Debug a UFT script in VBScript Debugger?

For effectively resolve the error, we need to use debug process of VBScript or UFT. It is a feature given to any IDE (Integrated Development Environment). Debugging refers to an activity to effectively figure out the root cause of any problem. The problem could be anything:

  • A Bug
  • A logic error
  • A mismatch in requirement
  • A wrong understanding.

It is very important while debugging and learning an Automation framework.

What is Debugging?

Debugging is a process by which we try to detect,locate and omit bugs from our code.

What is a Debugger?

A debugger is a two step process:

  • Identifying an issue
  • fix the issue and retest

A debugger is a tool (a set of codes) which provides insight of the running code in line by line manner.It places itself between compiler or runtime engine and real running of the program.

Even though the main objective of a debugger is to debug and find the issues in the code.But it is equally effective to understand the code, in terms of logic flow. Without debugging if we need to read and understand the code, it would be time consuming process.

Let’s see another important process called maintenance. During this phase, most of time the person who wrote the code does not fix the code or alter the code. Without a proper debug process, maintainability will go for a toss.

UFT Debug Process

UFT does have a solid debugger which will help us to debug. This post will not talk about UFT debugger but I will discuss on how we can debug .QFL or .VBS file outside of the UFT IDE.

Microsoft Debugger

Microsoft Script Debugger is a correct tool that can be used as a debugger of VBScript file on a system where UFT is not installed.

How to get Microsoft Script Debugger?

UFT/QTP has the debugger inbuilt with the IDE.In case if we are using UFT to debug our scripts,we do not need any other component or debugger.

Just in case , if we are debugging the .VBS file outside of UFT or we want to debug the .VBS file where UFT is not installed, We need to download the Microsoft Script Debugger from here.

After downloading, we need to install the debugger. As it is a Microsoft product, it is safer to restart the machine in order to take effect.

How to activate Microsoft Script Debugger?

The Microsoft debugger upon installation,attached to itself with WSH.Once we double click on the required .VBS file,the script will execute it via Microsoft Script Debugger.

We have one more option to use debugger via command line. To activate this feature we need to go to Start->Run->CScript.exe and open it.

Once we have opened it,we can use different switches to execute. Switches can be found here.

Microsoft Script Debugger has a great visual representation along with the components mentioned below.

WScript //x {path of the script}
WScript //d {path of the script}

//x switches ask WSH to bring debugger and breaks at the first line.
//d switches ask WSH to bring the debugger if it is needed. It activates the debugger at the breakpoint which are preset.

Components of Microsoft Script Debugger


This is the important component of the Microsoft Debugger. This will pause execution at a certain line, if we use this component and enable it.The objective of the breakpoint is to instruct WSH engine to stop the execution at the given breakpoint. This component is very useful as it only halts where we want it to halt leaving other lines of code unhalted but executed.

We can open the debugger manually and click on the suspected line.This is the line where the execution will halt.This feature is also available in UFT IDE.This line will be highlighted in yellow and a red circle or dot will indicate the execution is paused.

If we open the script using //x switch,the debugger automatically stops at the first line of the script.

We can setup multiple breakpoints in the script.

With Breakpoint enabled WSH will only stop if one of the below occurs:

  • It encounters an unhandled error
  • It reaches at the end of the script.
  • It gets a breakpoint provided by the user.

While breakpoint pauses the execution,these stepping features enables us to go slowly over the line of codes to identify the issue or understand the code.

Stepping is divided into three parts:

  1. Step into
  2. Step over
  3. Step out
Step Into

This component enables us to go into an user defined procedures,sub or a function.However we can not go into a function or sub defined by VBScript.Like Msgbox().So to step into a function or sub,the function or sub has to be in scope of the debugger.

This component goes inside of a custom function or sub or procedure.It starts executing line by line.

Step Over

Once we know the function is good to go,we can use this feature / component. This component instead of going inside the function or sub or procedure,it executes them and provides the output directly to the user.

Step Out

This feature finishes execution of a lower level procedure or sub or function.It then pauses at the starting of the next line.This is extremely useful when we step into a function or procedure and decide to leave or go out from it.


Step into,Step over,Step Out are just visual representation and stoppage of execution but underlying execution still takes place even if we skip from one component to another.

View Call Stack

This component stacks the nested sequence of function or procedure calls. It provides a hierarchical list of chain during execution of our script.It is useful when we have mutiple function calls in a chained manner.

WSH engine keeps track of all the calling function’s order until these functions gets completed. WSH traverses through the stack to determine the completion of the called functions.

How to Activate Call Stack?

Below steps needs to be performed while activating the call stack.

  • Put a breakpoint in the script.
  • Run the script in the debug mode.
  • While the control stops at breakpoint,click on the call stack option under view Menu.
  • The call stack window will appear and displays the stack information.

As it is a stack,we need to read from bottom towards up.

Command Window

This component enables us to query and view active variables. This is very useful when we want to check some value of the variablesĀ ,functions or sub.So theoretically, it is another strong debugging feature.The command window supports a special technique by which we can query the WSH.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 20
  • 28
  • 12
  • 23


Please enter your comment!
Please enter your name here