Learn UFT or QTP Step By Step

Learn UFT or UFT Step By Step
Learn UFT or UFT Step By Step

Learn UFT Step By Step:

The first thing you need to learn is VBScript...the basics..The best place to learn VB script is ---MSDN

However I have taken the required things from it...
What is a VBScript to a Automation Test Engineer?

VBScript (Visual Basic Script)

1. It is a scripting language scaled down version of Visual Basic
2. It runs on client side.
3. Basically a syntax based language. Most VB syntaxes run on this.
4. For our purpose we always save the file as “XYZ.vbs”

The very next topic is Variable:

1. Variable: Variables are container which holds value. Before using any variables we need to declare them.(This is a best practice.) We need use dim statement to decleare. The variable declaration is nothing but allocate some amount of memory for that variable to hold some value.
Like: dim c_ball,d_count
Again this declaration can be of three type as per scope:
1. Dim Statement
2. Public Statement
3. Private Statement
Dim can be accessible from the entire script.
Public statement variables are available to all procedures in all scripts.
Private statement variables are available only to the script in which they are declared
There is a separate term called constant.
Const variable_Name=”I am a good boy”
Now this variable_Name can be used anywhere. And its value is same. The scope is public bydefault.
VBScript in itself has a number of defined intrinsic constants like vbOK, vbCancel, vbTrue, vbFalse and so on

You can also declare a variable implicitly by simply using its name in your script. That is not generally a good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run. For that reason, the Option Explicit statement is available to require explicit declaration of all variables. The Option Explicit statement should be the first statement in your script.

Naming Restrictions 

Variable names follow the standard rules for naming anything in VBScript. A variable name:

1.Must begin with an alphabetic character.
2.Cannot contain an embedded period.
3.Must not exceed 255 characters.
4.Must be unique in the scope in which it is declared.

Scope and Lifetime of Variables 

A variable's scope is determined by where you declare it. When you declare a variable within a procedure, only code within that procedure can access or change the value of that variable. It has local scope and is a procedure-level variable. If you declare a variable outside a procedure, you make it recognizable to all the procedures in your script. This is a script-level variable, and it has script-level scope.

The lifetime of a variable depends on how long it exists. The lifetime of a script-level variable extends from the time it is declared until the time the script is finished running. At procedure level, a variable exists only as long as you are in the procedure. When the procedure exits, the variable is destroyed. Local variables are ideal as temporary storage space when a procedure is executing. You can have local variables of the same name in several different procedures because each is recognized only by the procedure in which it is declared.

Assigning Values to Variables 

Values are assigned to variables creating an expression as follows: the variable is on the left side of the expression and the value you want to assign to the variable is on the right. For example:

B = 200

Scalar Variables and Array Variables
Much of the time, you only want to assign a single value to a variable you have declared. A variable containing a single value is a scalar variable. Other times, it is convenient to assign more than one related value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses ( ) following the variable name. In the following example, a single-dimension array containing 11 elements is declared:

Dim A(10)

Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based, so this array actually contains 11 elements. In a zero-based array, the number of array elements is always the number shown in parentheses plus one. This kind of array is called a fixed-size array.

You assign data to each of the elements of the array using an index into the array. Beginning at zero and ending at 10, data can be assigned to the elements of an array as follows:

A(0) = 256
A(1) = 324
A(2) = 100
. . .
A(10) = 55

Similarly, the data can be retrieved from any element using an index into the particular array element you want. For example:

. . .
SomeVariable = A(8)
. . .

Arrays aren't limited to a single dimension. You can have as many as 60 dimensions, although most people can't comprehend more than three or four dimensions. You can declare multiple dimensions by separating an array's size numbers in the parentheses with commas. In the following example, the MyTable variable is a two-dimensional array consisting of 6 rows and 11 columns:

dim MyTable(5, 10)

In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns.

You can also declare an array whose size changes during the time your script is running. This is called a dynamic array. The array is initially declared within a procedure using either the Dim statement or using the ReDim statement. However, for a dynamic array, no size or number of dimensions is placed inside the parentheses. For example:

Dim MyArray()
ReDim AnotherArray()

To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension. In the following example, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place.

ReDim MyArray(25)
. . .
ReDim Preserve MyArray(30)

There is no limit to the number of times you can resize a dynamic array, although if you make an array smaller, you lose the data in the eliminated elements.

As UFT/UFT supports record and playback options. It is very important to understand about the recording options available in UFT/UFT In UFT/UFT we have three recording options.

  • Standard recording mode
  • Analog recording mode
  • Low level recording mode

Standard Recording Mode 

This is the default mode in UFT/uft which can record all operation. QuickTest's normal recording mode records the objects in your application and the operations performed on them. This mode is the default and takes full advantage of QuickTest's test object model, recognizing the objects in your application regardless of their location on the screen.
Navigation: Automation>Record
Select Record option on automation toolbar
Use short cut key (F3)

During recording UFT generates VbScript statements in Test Pane, Simultaneously it stores objects information into object repository. Steps for Normal recording: Steps for preparing a Test (through Recording):
1. Put AUT in base state
2. Select Record Option
3. It shows Record and Run Settings, Select type of Environment (Windows or Web)
4. Select Record Option (It shows two Options)
    4.1. Record and Run Test on any open window based applications
    4.2. Record and Run only on If we select first option it records on any opened application on Desktop. If we select Second option, it asks for the path of the AUT, After Providing the path it records only on that particular application.)
5. Click OK
6. Perform actions on AUT
7. Stop recording.
8. Save the Test

Here is the way to record in normal mode: 

1. Click the Record button or choose Automation > Record. If you are recording for the first time in a test and have not yet set your recording preferences (by opening the dialog box manually), the Record and Run Settings dialog box opens. It is divided by environment into several tabbed pages.
2. To choose an environment, click a tab.

3. Set the required options, as described in the following sections.

4. To apply your changes and keep the Record and Run Settings dialog box open, click Apply.

 5. When you have finished the operation, click OK to save your changes and start recording. Guidelines for Modifying Record and Run Settings After you set the record and run settings for a test, the Record and Run settingsdialogbox will not open the next time yourecord operations in that test. If needed, you open the Record and Run Settings dialog box by choosing Automation > Record and Run Settings. You should set or modify your record and run preferences in the following scenarios: • You have already recorded one or more steps in the test and you want to modify the settings before you continue recording. • You want to run the test on a different application or browser than the one you previously set in the Record and Run Settings dialog box. If you change the record and run settings for additional recording sessions, confirm that you return the settings to match the needs of the first step in your test before you run it.

All about the web options:

Record and run test on any open browser Instructs QuickTest to record on any open Microsoft Internet Explorer browser and run on any open supported Web browser (refer to the QuickTest Professional Readme for information on supported browsers). Note: You must open the Web browser after you open QuickTest and select this option.TipYou can instruct QuickTest to ignore selected browsers that are open during the record and run session. Open the following address when a record or run session begins Instructs QuickTest to open a new browser session to record and run the test using the specified URL address. When recording a test, the address is opened in a Microsoft Internet Explorer browser. When running a test, the address is opened in the browser type specified in the Open the following browser when a run session begins box. NoteIf you define a value for the URL_ENV environment variable, that value overrides the value specified here during a run session. Open the following browser when a run session begins Instructs QuickTest to open the specified browser type when running a test: • Microsoft Internet Explorer • Netscape 8.x • Firefox 1.5 Notes: Only those browsers currently installed on your computer are available in the list. If you define a value for the BROWSER_ENV environment variable, that value overrides the value specified here during a run session. Do not record and run on browsers that are already open Instructs QuickTest not to record or run tests on any browsers that are already open prior to the start of the record or run session (and prior to opening QuickTest). Selecting this option also prevents you from viewing the properties of these browsers using the Object Spy. Close the browser when the test closes Instructs QuickTest to close the browser window specified in the Address box when the test closes.

All about Window based option:

Option Description Record and run test on any open Windows-based application Instructs QuickTest to record and run on any open Windows-based application. Note: Make sure that all the applications on which you want to record are currently closed. QuickTest can record on the applications that you open manually only after you select this option and click OK. Instances of these applications that are already open when the Record and Run Settings dialog box opens may be ignored or may not be recorded correctly. Record and run only on Instructs QuickTest to restrict its record and run operations to one or more of the following options:

Applications opened by QuickTest:

This option records and runs only on applications invoked by QuickTest (as child processes of QuickTest). For example, applications opened during a record or run session using a SystemUtil.Run statement, or using a statement such as Set shell = createobject("wscript.shell"); shell.run "notepad".

Applications opened via the Desktop (by the Windows shell):

This option records and runs only on applications that are opened via the Windows Desktop. For example, applications opened from the Windows Start menu, by double-clicking executable files in the Windows Explorer, by double-clicking ashort cuton the Windows Desktop, or by clicking icons on theQuick Launch bar.

Applications specified below:

This option records and runs only on applications listed in the Application details area. This is the recommended option to use. When working with standard Windows applications only, you can manually add steps to your test and then run them, even if you select this option and leave the Application details area blank (or if the list does not contain the application for which you want to add a step). Note: Make sure that all the applications listed in the Application details area are currently closed. QuickTest can record only on the instances of the specified applications that are opened after you select this option and click OK. Instances of these applications that are already open when the Record and Run Settings dialog box opens may be ignored or may not be recorded correctly. Application details Lists the details of the applications on which to record and run the test. For more information on the details displayed. If you define values for one or more environment variables, those values override the values in the Windows Applications tab during a test run. By these above methods we can get the script but in the object repository we might get extra unnecessary objects. So to avoid this a little advanced approach will be to add those required object to OR[Object repository] and then perform normal recording. Shortcut Ctrl+R or by navigating to Resources to Object repository.


It records User Mouse and Keyboard operations on AUT with respect to objects, but unable to record continuous mouse operations like Digital Signatures, graphs, paints etc. When working with specific types of objects or operations, however, you may want to choose from the following, alternative recording modes:

Analog Recording Mode: 

 Here UFT can identify the object but can not record.For example UFT can identify the paint/drawing bar normal mode but can not draw the picture or can not draw a signature by normal mode.To solve such problem we will choose analog recording mode. UFT will identify the object and the analog operation over it.It will record the keyboard and mouse movement on the recognized window. Similarly,when testing signature we use Analog Recording Mode. Analog Recording enables you to record the exact mouse and keyboard operations you perform in relation to either the screen or the application window. In this recording mode, QuickTest records and tracks every movement of the mouse as you drag the mouse around a screen or window. We can use this mode for recording continuous mouse operations. however it does not generate steps for each operation, generates total user actions in a Track File. The Track file is not editable. There are two mode of recording: 1. Relative to specific window 2. Relative to screen

Relative to window: 

Activate this option if and only if operations performed on UAT located within one window.During this mode UFT tries to identify the window location and can perform operations(record the analog step) even if it is located in different location. Interestingly UFT does not record any keyboard operation or mouse movement outside this window. Active Screen image of the final state of the window is captured.

Relative to Screen: 

This is a very rare scenario where we need to perform some analog recording with respect to screen. This is applicable during run time that is execution time also.It can also be possible if the AUT is having multiple windows opened. No active screen shot is taken/captured during this type of recording

Best to use while Automating: 

1. Paint operation
2. Drag and drop


1. Keep tool under recording mode
2. Automation >Analog Recording OR Use Short cut Key (Shift + ALT+F3)

 Steps for preparing a TEST (through Analog Recording): 

1. Launch AUT (or we can launch AUT through UFT)
2. Select Record option
3. Automation>Analog Recording
4. Analog Recording Settings Dialog box opens (In this Dialog box two options available.    4.1. Record relative to the screen
 4.2. Record relative to the following window If we select first option UFT records User operations with respect to Desktop co-ordinates. If we select Second option, we have to show the window (AUT), after showing the Window it records with respect to that window co-ordinates.)
5. Select any one option in the dialog box and click Start Analog record. 6. It records User actions 7. Stop Recording This mode is useful for recording operations that cannot be recorded at the level of an object, for example, recording a signature produced by dragging the mouse. Note: You cannot edit Analog Recording steps from within QuickTest. To execute this UFT invokes RunAnalog command like-
Desktop.RunAnalog "Track1"
' This is for Relative to the scren but for relative to a window the code will be--
Window({name of the window}).RunAnalog "Track2"

Both these two recoding mode eats up huge disk space. So please do not use these if not required. Mixing of normal analog mode of recording is possible and we can switch to these modes if required.

Low Level recording:
UFT can not identify the object under test.Hence it can not proceed with recording.As UFT can not identify or recognize the application under test,Analog Recording Mode can not be operated. So if we need to test such application,we need to activated Low Level recording.By enabling this mode of recording, UFT will identify obejects and by default class window or win Object and will record all keyboard and mouse operation. Low Level recording enables you to record on any object in your application, whether or not QuickTest recognizes the specific object or the specific operation. This mode records at the object level and records all run-time objects as Window or WinObject test objects. Use Low Level Recording for recording in an environment or on an object not recognized by QuickTest. You can also use Low Level Recording if the exact coordinates of the object are important for your test. In this level of recording UFT identifies co ordinates mostly to record and run. Note: Steps recorded using Low Level Recording mode may not run correctly on all objects. It records some operations on Non-supported environments apart from Normal operations. This mode records at the object level and records all run time objects as window or winobject Test objects. Use Low Level Recording for recording in an environment not recognized by UFT.


1. Keep tool under recording mode
2. Automation >Low Level Recording

Steps for preparing a TEST (through Low Level Recording):
1) Launch AUT (or we can launch AUT through UFT)
2) Select Record option
3) Automation> Low Level Recording
4) Perform options on AUT
5) Stop Recording
6) Save the Test So similarly between analog and low level recording,in both cases UFT uses keyboard,mouse and work on co-ordinates.But difference is in Analog mode UFT can identify the object in UAT but in Low level recording ,it can not. One more important aspect of low level recording is it majorly depends on the co-ordinates. So in normal mode if the co ordinates changes for an object,still UFT will identify the object and performs operations. But in such case where co ordinates like location of the object is very important, we can use low level recording to check the location of the object. Mostly It supports Click,DbClick,Drag,Drop,Type,Activate,Minimize,Restore etc.

Steps to follow before you start recording:

1. Before you record a test, confirm that your application and Quick Test are compatible to each other.
2. Start QTP Check the required Addin in Add ins manager. Else add those.Like for java application we need to have JAVA addin. While QuickTest loads your selected add-ins, the QuickTest splash screen is displayed. This may take a few seconds. confirm that the Web Add-in is selected, and clear all other add-ins. Click OK to close the Add-in Manager.
3. Make sure the application is ready.i.e.Make sure your application displays elements on which you want to record, such as a toolbar or a special window pane, for example, and that your application options are set as you expect for the purposes of your test.
4. You should also view the settings in the Test Settings dialog box (File > Settings) and the Options dialog box (Tools > Options) to ensure that Quick Test will record and store information correctly.
5. if you are using Internet Explorer as your browser, the AutoComplete option is cleared for user names and passwords .
6. Please close all other browsers.
7. If the Welcome window opens, click Blank Test.Otherwise, choose File > New, or click the New button.

Get Values or SetValues and checkpoints:

I not a big fan of Checkpoints available in UFT or QTP as they are unreliable at times.

Object Repository in UFT:

Refer this article to get Object repositories in UFT.

Environment Variable in UFT:

Read about Environment variables here:
Learn UFT or QTP Step By Step Learn UFT or QTP Step By Step Reviewed by Animesh Chatterjee on September 14, 2009 Rating: 5

1 comment:

  1. Hi Animesh,

    This is kumar from chennai. I am a Newbie in QTP. I found your blog in http://askqtp.blogspot.com/2009/09/learn-qtp-step-by-step.html I have following questions poke in my mind. Pls answer my questions:

    a) How to start QTP (Before i start what are things i should do)
    b) Could you pls give me 'Sample automation frame work' and how to create?
    c) Could you pls give me a any QTP use guide (If you have)



Powered by Blogger.