You are on page 1of 85

HP QTP - UFT GUIDE

TABLE OF CONTENTS

1. Introduction
2. QTP / UFT IDE
3. Record and Playback UFT/QTP Script
4. Keyword and Editor View in QTP/UFT
5. Local & Shared Object Repository in QTP/UFT
6. How to Replay a Script in QTP/UFT with Example
7. Parameterization in QTP/UFT with Example
8. Checkpoints in QTP/UFT with Example
9. IF, Else, End IF, Exists, Switch in QTP/UFT with Example
10. Reporter.ReportEvent in QTP/UFT with Example
11. Report Formats
12. Screen Capture
13. Export Report Results, Automatically
14. Understand SystemUtil.Run, SetSecure, Set, Type: QTP/UFT Examples
15. Object Repository & Object Operations
16. Object Spy, GetRoProperty, GetToProperty in QTP/UFT with Example
17. Virtual Objects
18. How Object Identification works in QTP/UFT?
19. Smart Identification in QTP/UFT with Example
20. Ordinal Identifier in QTP/UFT: Object Identification Example
21. Actions in QTP
22. Types of Recording Modes in QTP/UFT
23. How to use Functions in QTP/UFT
24. Step Generator
25. Synchronisation Points
26. How to use Transactions in QTP/UFT
27. Environment Variable in QTP (UFT) with Example
28. Regular Expressions
29. Debugging
30. VB Script Introduction
31. Variable Declaration
32. Option Explicit
33. Arrays
34. Msg box
35. Input Box
36. Different Loops
37. Folder Operations
38. File Operations
39. How to Import, Read, Change Data from EXCEL in QTP/UFT
40. String Functions
41. Date Functions
42. Function Usage
43. Sub Procedure
44. Frameworks
45. How to print Output Values in QTP/UFT with Example
46. How to use Recovery Scenario in QTP/UFT with Example
47. Optional Step in QTP/UFT with Example
INTRODUCTION TO HP QTP/UFT
 QTP is an automated functional Testing tool that helps testers to execute automated
tests in order to identify any errors, defects or gaps in contrary to the expected
results of the application under test.

 It is an icon-based tool that automates the regression and Functional Testing of an


application.

 QTP Testing is based on scripting language VB script. Micro Focus’s UFT uses VBScript
to automate applications

Advantages of QTP Automation:


 It supports record and playback.
 It has excellent object identification process or mechanism.
 Different types of suites like Smoke, Regression, Sanity can be easily maintained.
 It supports XML.
 Test reporting is possible through QTP for analysis purpose.
 Easy to maintain.

Differences between Selenium & QTP / UFT:


Feature Selenium HP QTP / UFT
License Open Source Required

Test Support Supports automation only for Supports tests on both web and
web – based applications. desktop applications.
Supported Java, C#, Ruby, Python etc. VB Script
programming
languages

Supported Android, iOS, Windows, Linux Windows


Environments etc.
Object Repository Absent Built – in Object Repository
Test Report Relies on External Tool for Built – in test report generation
Generation generating test reports.
HP QTP / UFT IDE
 Important components of IDE:
i. Menu Bar
ii. Properties Window
iii. Document Tab
iv. Solution Explorer
v. Toolbox tab
vi. Output Tab
vii. Active Screen
viii. Data Tab

1. Menu Bar:
a. File Menu:

i. New: Using File –>New, you can create a new Test, Business
Component, Solution, Function Library or an Application Area.
ii. Open: Using this option, you can open an already created Test,
Business Component, Solution, Function Library, Application Area or
any file type that can be opened in UFT.
iii. Add: You can add a new Test, Business Component, Function Library,
Application Area to a Solution.
iv. Close: Close the currently opened asset in the view. (Ctrl + F4).
v. Close Solution: Close the Solution. (Ctrl + Shift + F4).
vi. Save <Test Name>: Save the current test.
vii. Save <Test Name> As: Save the current test with a different name
(.tsp) extension.
viii. Save All: Save all testing documents in the Solution Explorer.
ix. Save (Other): Save a test with resources including Active Screen.
x. Recent: Shows a list of tests recently opened on your machine.
xi. Export Test: Export a test into a zip format.
xii. Import Test: Import a test from a zip format.

b. Edit Menu:

i. Format: Out of all the options present under Format (as shown
below), you would be using Comment and Uncomment more often.

ii. Code Snippet: This is a helpful tool for VB Script beginners. Using
Code Snippet option, you can quickly copy syntax for various types of
conditional and logical statements found in VB Script.
c. View Menu:

d. Search Menu:

e. Design Menu:
f. Record Menu:

g. Run Menu:

h. Resources Menu:
i. ALM Menu:

j. Tools Menu:

2. Solution Explorer: The Solution Explorer is a hierarchical tree of all actions and
tests in the current test, with their references, events, and flows.
3. Data Table: You can enter the data related to your test through data-tab from the
menu-bar at the bottom of the window. This panel is the tree hierarchy of data
sources that can be used with a test.

4. Action Tab: The “Action” tab gives details of test code.


RECORD & PLAYBACK UFT/QTP
SCRIPT
Steps to Record a Script in UFT / QTP:
1. In Micro Focus UFT click the record button. The Record and Run settings Dialog Box
Open. This box opens automatically each time you begin recording a new test.

2. Record & Run settings shows a tab corresponding to add-ins installed and loaded for
your test. So, for example, if you have SAP Add-in Installed and loaded you will see
an SAP tab. The Windows Application tab is always available and is used for
environments, such as Visual Basic, ActiveX, and terminal emulators.

For any Environment, the Record and Run settings can be classified into two generic
groups:

i. Record & Run on ANY window belonging to that particular environment.


ii. Record & Run on a SPECIFIC window belonging to that particular
environment – which is the recommended Option.
Once settings are done, QTP remembers and uses the same settings for additional
record sessions on the same test, unless you manually open the Record and Run
Settings dialog box to modify the settings.
3. Click okay. QTP Starts Recording Mode.

4. Record the test steps. Once the action is completed, go to the record panel and click
‘Stop’. The script will be generated.

5. Click ‘Playback’ button to playback the script.

6. The result window will show the execution time stamp, pass, and failed steps.
KEYWORD VIEW AND EDITOR
VIEW IN QTP/UFT
Keyword View:
 The Keyword View is comprised of a table-like view where Each step is a separate
row in the table and Each column represents different parts of the steps.

 Item Column contains the item on which you want to perform the step. This column
uses icons displays the hierarchy of the GUI object on which operation is performed.

 Operation Column contains the operation to be performed on the item.

 Value Column contains the argument values for the selected operation.

 HP QTP automatically documents each step for easy understanding in the


Documentation Column.

Editor View:
 In the Editor View, each line represents a Test Step in VB Script. Consider the
following code

Dialog("Login").WinEdit("Agent Name:").Set "Gur9"

 An Object’s Name is displayed in parentheses following the Object Type. Here the
Object Name is Login and Object Type is Dialog.

 Objects in Object Hierarchy are separated by a “dot”.

 Dialog Box is the Parent Object where as WinEdit is the Child Object.

 The Operation performed on the object is always displayed at the end of the
statement followed by any values associated with the operation. Here the word
“Gur9” is inserted in the AgentName Edit Box using the Set Method.

 Syntax for a statement in Editor View:

ParentObject(Name).ChildObject1(Name)...ChildObjectN(Name).Operation
LOCAL & SHARED OBJECT
REPOSITORY IN QTP / UFT

 Object Repository is a collection of Test Objects and information that is recognized


by QTP for working on it.

 When a user records a test, the objects and their properties are captured by default.

 Types of Object Repositories:

i. Local Object Repository


ii. Shared Object Repository

Local Object Repository:


 Local Object Repository is the default object repository.
 It is specific to actions and can be used only for a particular action.
 Local Object Repository cannot be reused.
 Local Object Repository can be opened by traversing to Resources → Object
Repository.
Shared Object Repository:
 Global or Shared Object Repository is preferable when an application is dynamic and
object description change frequently.

 Shared object repository is more commonly used in automation projects.

 To create an object repository:

i. Creating a Shared Object Repository


ii. Associating a Shared Object Repository
iii. Editing a Shared Object Repository

1. Creating a Shared Object Repository:

iv. All repositories are local by default. To create a Shared Object Repository, in
the Object Repository Dialog Box, Click File > Export Local Objects.
v. Repository files have an extension .tsr .Give a suitable name and save.
vi. The Shared Repository File is now created.

2. Associate a Shared Object Repository:

vii. Next step is to associate the repository to your test, which enables you to use
it.
viii. To associate a repository with a test, Click Resources > Associate Repository.
ix. You can select the Repository to associate with Actions available in your test.
x. Now you can now use this shared repository to develop your test.

3. Editing a Shared Object Repository:

xi. You can use the Object Repository Manager to Edit a Share Repository.
xii. Select Resources > Object Repository Manager. Open the Object Repository.
xiii. By Default, Repository is opened in Read-only mode. To enable editing click
File > Enable Editing.
xiv. Once editing is enabled you can all the operations like cut, copy, paste,
rename objects etc that you can also do in Object Repository.
HOW TO REPLAY A SCRIPT IN
QTP / UFT

 Once the script is recorded, you need to REPLAY the script to ensure the test steps
have recorded correctly. When you click the Run Button, a Run Dialog Box Opens.

 The Run Box enables you to specify the location in which you want to save the run
session results.

 It displays the default path and folder name in which results are stored. By default
results are stored in Test Folder. A new sub-folder is created with the name RESn.
The number n is incremented for each run. You can accept the default settings.

 Temporary run results folder options save the results of the QTP program run in a
temporary folder. This option overwrites any results previously saved in this folder.
Its recommended that while developing your test script choose the Temporary
option and once the script is baseline you can use the new folder option.

 One you click run, execution starts. In HP QTP/UFT window you can see a yellow
marker pointing at the step which is currently being executed.
PARAMETERIZATION IN QTP /
UFT

 QTP provides us to pick different test inputs at a run time. This process of providing
different input values through external parameters is called as parameterization.

 Types of Parameterization in QTP:

i. Data Table parameters


ii. Test / Action parameters
iii. Environment Variable parameters
iv. Random Number parameters

 Ways to perform Parameterization:


i. Using Keyword View. Click on Parameterize icon:

Value Configuration Dialog Box Opens. Currently, the value is set to a Constant. Click
on Parameter Radio Button. QTP assigns a default name to this parameter. You can
give a name of your choice and then click “OK.”
In the Global Sheet, a column with Header “Agent Name” and value Guru is created.
You can enter more values for this parameter.

When you click on “expert view” you will see that “Agent Name” is replaced by
“Guru”, and the type of sheet used.

Likewise, you can also parameterize the argument Password and enter different test
data sets.
What this Datasheet means is QTP will iterate the same six steps that we have
recorded three times. During the first iteration, it will use the data in the first row.
During the second it will use the data in the second row and so on.

The results will show a summary of the 3 iterations.

ii. Using Data Driver:

The data driver enables you to quickly parameterize several property values
for test objects, checkpoints and method arguments containing the same
constant value within a given action.

To parameterize a value using Data Driver:

1. Display the action you want to parameterize.


2. Navigate to Tools -> Data Driver
Quick Test scans the test for constants before the Data Driver opens. The data driver
displays the Constants list for the action. For each constant value, it displays the
number of times the constant value appears in action.

3. If you want to parameterize a value that is not currently displayed in the


list click Add Value. The Add Value dialog box opens. Enter a constant
value in the dialog box and click OK. The constant is added to the list.
4. Select the value you want to parametrize from the Constants list and click
Parametrize. The data driver wizard opens.

5. If you selected Step-by-step parametrization, click Next. The parametrize


the selected step screen opens. If you selected Parametrize all, the
parameter option is enabled in the Configure value area. Select your
parametrization preferences the same way that you would for an
individual step.
6. In the Step to parametrize area the first step with an object property or
checkpoint value containing the selected value is displayed in the test
tree on the left.

7. Click next to parametrize the selected step and view the next step.

8. Click Skip if you do not want to parametrize the selected step.

9. Click Finish to apply the parametrization settings of the current step to all
remaining steps containing the selected value. The Data Driver Wizard
closes and the Data Driver main screen shows how many occurrences you
selected to parametrize and how many remain as constants.
10. When you are finished with the parametrization constants click OK. The
parametrization options you selected are applied to your action.

Advantages of Parameterization:
 Parameterization allows us to pick different values at run time.
 It Reduces Time and Effort.
CHECK POINTS IN QTP / UFT
 A checkpoint is a verification point that compares the current value with the
expected value for specified properties of an Object.

 If the current and expected value match it generates a PASS status otherwise FAIL
status.

 To add checkpoints, navigate to Design -> Checkpoint and select the required
checkpoint.

Types of Checkpoints in UFT:


1. Standard Checkpoint:

 It compares the expected values of object properties captured during


recording to the object’s current values during a run session.

 Default Checkpoint Timeout: 10 sec.

Adding the Standard Checkpoint:


Select the Standard Checkpoint option, the mouse pointer will turn into a hand, click
on any object like a hyperlink, Textbox, radio button, or on any text of the page, the
Checkpoint property window will be displayed. You can select the properties of the
object that you want to validate at runtime and click the OK button.

UFT will automatically add a step in the current action of the Test.

2. Text Checkpoint:

 Used to check expected text in a web-page or application. This text


could be from a specific region of the application or a small portion of
text displayed.

 Default Checkpoint Time: 10 sec.

Adding Text Checkpoint:


To add a Text Checkpoint, select the Text Checkpoint option from the recording
session wizard.
The mouse pointer will turn into a hand, click on the object for which you want to
validate the text. UFT will capture the text and the same will be displayed in the Text
Checkpoint Properties window.

By default, UFT ignores the cases of the text string to be validated. You can check
and uncheck required checkboxes and click on the OK button. The checkpoint will be
added to the test script.

3. Text Area Checkpoint:

 The Text Area Checkpoint enables you to check that a text string
appears within a defined area in a Test application, according to
specified criteria.

 By adding Text Area Checkpoint in UFT you can validate static as well
as dynamic texts in UFT.

Adding Text Area Checkpoint:


To add a Text Area Checkpoint, select the Text Area Checkpoint option from the
recording session wizard.
The mouse pointer will be changed into a cross icon to let you select the required
text under the specific area of application and leave the mouse pointer.

The Text Area Checkpoint Properties window will be displayed with the text string
that was selected within the defined area. Click on the “OK” button.

The Text Area Checkpoint will be added to the test script.

4. Bitmap Checkpoint:

 It helps a user in checking the bitmap of an image or a full web page.


It does a pixel by pixel comparison between actual and expected
images.
 Default Checkpoint Time: 10 sec.

Adding Bitmap Checkpoint:


To add a Bitmap Checkpoint, select the Bitmap Checkpoint option from the recording
session wizard & click on the required object.

Select the required object from the Bitmap Checkpoint window and click on the OK
button. The entire object bitmap will be captured and display in the Bitmap
Checkpoint properties window.

Click on the OK button, The checkpoint will be added in the script.


IF, ELSE, IF ELSE IF, EXISTS,
SELECT IN QTP/UFT
1. IF Statement:

 To execute only one statement when a condition is true.

 Syntax:

IF THEN
set of statements
END IF

 Example:

Dim a,b
a=8 : b=6
if a>b then
msgbox “a is greater than b”
End if

2. ELSE Statement:

 It is to execute more than one statement when a condition is true.


 Syntax:

IF THEN
set of statements
ELSE
set of statements
END IF

 Example:
Dim a,b
a=3 : b=6
if a>b then
msgbox “a is greater than b”
Else
Msgbox “Stay tuned to Software Testing Material”
End if

3. IF ELSE IF Statement:

 Syntax:
IF THEN
set of statements
ELSEIF Then
set of statements
ELSE
set of statements
END IF

 Example:

Dim a,b
a=8 : b=6
if a>b then
msgbox “a is greater than b”
Elseif a=b then
Msgbox “a is equals to b”
Else
Msgbox “a is not equals to b”
End if

4. Select Statement:

 It’s an alternative to IF-THEN-ELSE. It makes code more efficient and


readable.

 Syntax:

SELECT CASE EXPRESSION


CASE EXPRESSION1
set of statements
CASE EXPRESSION2
set of statements
CASE ELSE
set of statements
END SELECT

 Example:
InputValue = Inputbox(“Enter the value: red or green or yellow”)
Select case lcase(InputValue)
Case “red”
Msgbox “stop”
Case “green”
Msgbox “go”
Case “yellow”
Msgbox “wait”
Case else
Msgbox “Invalid”
End Select

5. EXISTS Statement:

 Exist statements in QTP return a true/false indicating whether or not


an object currently exists. the parameters which we use for exist is
the timeout seconds for which QTP will check for the existence of the
objects which is like Exists(1),Exists(3)…

 If you use Exists(3) as in your statement QTP will wait for 3 seconds
and check if object exist.

 If you don’t use the parameter and simple use Exists, QTP will take the
default value which is 20 seconds.
REPORTER.REPORTEVENT IN
QTP/UFT
 Reporter.ReportEvent Statement is used to send desired events (like Pass, Fail, etc)
and custom messages in the run results of UFT.
 Syntax:

Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

 Event Status can have values:


i. 0 or micPass sends a pass status to test result window.
ii. 1 or micFail sends a fail status to test result window.
iii. 2 or micDone sends a message to test result window without affecting the
Pass/Fail status.
iv. 3 or micWarning sends a warning message to the result window.

 ReportStepName: Step name that is displayed in the Run Results window. Generally
used to write the expected result.

 Details: It shows the description of the run results event. Generally used to write the
actual result.

 ImageFilePath: This is an optional parameter. Provide the path and filename of the
image to be displayed in the run results. Supported image formats are BMP, PNG,
JPEG, and GIF.

 Examples:

 Reporter.ReportEvent micPass,"Flight Booking Order","The order


placed successfully"

 Reporter.ReportEvent 1,"Flight Booking Order should be


placed","Flight Booking order was not placed"
REPORT FORMATS IN QTP / UFT

 Types of Report Formats:


i. HTML Report
ii. Run Results Viewer Report

 In order to set the required report formats, navigate to Tools -> Options -> Run
Sessions -> Report Format -> Select any of the report format -> OK.

SCREEN CAPTURE IN QTP / UFT


 To enable screen capture, navigate to Tools -> Options -> GUI Testing tab -> Screen
Capture.

 Change the option to ‘Always’.

 Works only when we select Run Results Viewer Report.

EXPORT REPORT RESULTS


AUTOMATICALLY IN QTP / UFT
 In order to export results automatically, navigate to Tools -> Options -> General Tab -
> Run Sessions.

 Under report format, select Run Results Viewer Report.

 Select Automatically export run results when run session ends.

 Click on Configure button. Select the report type.


SYSTEMUTIL.RUN, SETSECURE,
SET, TYPE IN QTP / UFT
1. SystemUtil.Run:

 SystemUtil.Run is an inbuilt QTP command that lets you run a file or


an application.
 Syntax:
SystemUtil.Run “Path of file”.

2. Set Method:

 The Set method is used in 3 different contexts:

1. Setting the value of an edit box:

Syntax: (Object Hierarchy).SET "Value"

Example:

Dialog ("Login").WinEdit("Agent Name").Set "Agent1"

2. Setting the value of an edit box:

Syntax: (Object Hierarchy).SET

Example:
Window("Flight Reservation").WinRadioButton("Business").Set

3. Setting the value of an edit box:

Syntax: (Object Hierarchy).Set "ON/off"

Example:
Window ("Flight Reservation"). Dialog("Open
Order").WinCheckBox("Order No.").Set "ON”

3. Click Method:

 The Click method is used to click on an object, usually buttons.

 Syntax:

(Object Hierarchy).Click

 Example:

Window("Login").WebButton("Ok").click
OBJECT OPERATIONS IN QTP /
UFT
1. Save Object Repositories to XML Format:

 To reduce the size of object repository, save it in XML format. User


can export or import same or different object repository into XML
format. The Same object repository can be imported into XML and
can be edited/deleted and exported back to XML.

 Navigate to Shared Repository window, go to File -> Import to XML or


Export to XML.

2. Comparing Object Repositories:

 Object repositories can be compared using Object Repository


Comparison Tool. This comparison is helpful for users to see two
different object repositories objects, properties and their values, to
decide which repository is helpful for test.

 To get this tool, go to Resources > Object Repository Manager.


 Form Object Repository Manager window, access Tools > Object
Repository Comparison Tool.

 The Object Repository comparison Window opens, here user has to


choose two Object Repository files for comparison and click on OK.

 It shows the Comparison and displays the differences one by one as


shown below. Close the “Comparison Statistics”.
 Next, after closing “Comparison Statistics”, click on “Filter” button.
Filter dialog box opens with three parameters- unique objects,
identical objects, and partial match objects. Confirm that all three
options should be selected.

4. Merging Object Repositories:

 Some time, it becomes necessary to merge object repositories with


each other. In this case, object repository adds additional overheads.
 In UFT, go to Resources > Object Repository Manager. In the opened
Object Repository Manager window, go to Tools > Object Repository
Merge Tool.

 The Object Repository Merge Window opens. Here, select two Object
Repository files for merge and click OK.

 Next, Merge Statistics shows with conflicts and merge summary,


shown in the figure below. Close the Merge Statistics dialog box.

 Display objects and their properties by using filter options; show all
objects, or show only conflicting objects.
OBJECT SPY, GETROPROPERTY,
GETTOPROPERTY IN QTP/UFT
1. Object Spy:

 Object spy is a feature in QTP using which you can view both the test
and run-time object properties and methods.

 Object Spy gives the complete hierarchy of the object you have
selected.

 Object Spy can be accessed from the tool bar as shown below:

 Clicking the Object Spy icon, the Object Spy Dialog box opens. The
Objects can be added to the repository on clicking the pointing hand.

 After Spying the object, the object hierarchy will be shown. Let us say,
we are spying the "Numbers" link at "http://easycalculation.com/".
The Object properties will be as shown below.
 After Spying an object, click the "Highlight" option to highlight the
object in the application.

 For adding the object into the Object Repository, click the "Add
objects" button in the Object spy dialog.

 The properties and its values are displayed for the selected object in
the dialog box, which should be unique for QTP, to recognize the
objects while the script executes.

 The supported operations on the object can be retrieved by clicking


the operation tab. Operations such as "click" for a button, "Set" for a
text box are retrieved from the "operations" tab as shown below
2. GetRoProperty:

 GetROProperty is used to retrieve the current property value of an


object in the application during run session.

 Syntax:

object.GetROProperty (Property Name)

 Return Type: A variant value.

 Example:

You are supposed to check the default selected value of a WebList


object. For this example, I will use the Mercury Tour Demo
Application.

Using Object Spy you can look for the required object property that
you want to retrieve at run-time from the application.
We can use the “selection” property as it showing the current value of
the WebList object. Write the following code to retrieve the value of
the selected item from the fromPort WebList box.

strListBoxUtem =Browser("Welcome: Mercury Tours").Page("Find a


Flight: Mercury").WebList("fromPort").GetROProperty("selection")

msgbox strListBoxUtem

In the message box, the output would be “Acapulco“

3. SetToProperty:

 SetToProperty can be used to set the value of the specified


description properties in the test object description that is there in
the Object Repository.

 Syntax:

object.SetTOProperty (Property, Value)

 Example:

We will Set the HTML ID for fromPort WebList object.

Browser("Welcome: Mercury Tours").Page("Find a Flight:


Mercury").WebList("fromPort").SetTOProperty "html id","123"
4. GetToProperty:

 GetToProperty is used to retrieve the value of the specified


description properties from the test object description.

 Syntax:

object.GetTOProperty(Property)

 Example:

strToProp=Browser("Welcome: Mercury Tours").Page("Find a


Flight: Mercury").WebList("fromPort").GetToProperty("html
id")

Difference between GetRoProperty & GetToProperty:


 GetRoProperty retrieves the run-time value of an object property from the object in
the application.

 GetToProperty retrieves the value of the specified description properties from the
test object description that means it retrieves the object property that is stored in
the object repository. It can’t return the runtime property of a Test Object from the
application.

 For example, If we spy the object property of fromPort WebList box, its HTML ID
property value will be shown as empty.
 We will set an “html id” value for it and try to retrieve its value using both
GetRoProperty and GetToProperty.
Browser("Welcome: Mercury Tours").Page("Find a Flight:
Mercury").WebList("fromPort").SetTOProperty "html id","123"
strRoProp=Browser("Welcome: Mercury Tours").Page("Find a Flight:
Mercury").WebList("fromPort").GetRoProperty("html id")
Print "Runtime value of html id: " & strRoProp
strToProp=Browser("Welcome: Mercury Tours").Page("Find a Flight:
Mercury").WebList("fromPort").GetToProperty("html id")
Print "Test Object value of html id: " & strToProp
If we execute the above code the output will be different for both. The GetRoProperty will
return an empty value. However, the GetToProperty will return to value 123.
VIRTUAL OBJECTS IN QTP / UFT
 Sometimes, an application under test may contain standard window object but are
not recognized by QTP.

 Under these circumstances, objects can be defined as virtual object of type button,
link etc. so that user actions can be simulated on the virtual objects during
execution.

 Example:

Let us say we are automating a scenario in Microsoft Word. I activated MS word


application and I click on any icon in the ribbon. For example, on the Ribbon, Insert
tab is clicked and then the user clicks the "Picture" button. A button is recognized as
WinObject; hence, importance of virtual objects is pronounced.

Window("Microsoft Word").WinObject("Ribbon").Click 145,45


Window("Microsoft Word").WinObject("Ribbon").WinObject("Picture...").Click
170,104

Creating a Virtual Object:


 In such scenarios, virtual Objects are created using Virtual Object Manager or New
Virtual Object from "Tools" >> "Virtual Object" >> "New Virtual Object" and click the
"Next" button.

 Map the Object against the Class Type and click "Next".
 Click "Mark Object" Button. A cross hair cursor would appear and mark the object
that you would like to map and click "Next".

 Select the parent of the Virtual object and click "Next".


 Name the collection in which you would like to store the virtual object and click
"Finish".

Virtual Object Manager:


 Virtual object Manager manages the collections of Virtual objects. Testers can add or
Delete the Virtual Objects from the Virtual Object manager.

 Navigation to Virtual object Manager: "Tools" >> "Virtual Object Manager" as shown
below:
Using Virtual Objects:
 After creating the Virtual Objects, the created object can be used as shown below:

Window("Microsoft Word").WinObject("Ribbon").VirtualButton("button").Click

Virtual Object Limitations:


 QTP does not support virtual objects for analog or low-level recording.

 Checkpoints cannot be added on Virtual Objects.

 Virtual Objects are not controlled by Object Repository.

 Object Spy cannot be used on Virtual Object.

 Though we map an object to a particular class (button or List), all the methods of the
native objects are not supported by Virtual objects.
HOW OBJECT IDENTIFICATION
WORKS IN QTP/UFT
 QTP also uses a “human” like technology for object identification. During record
time, QTP tries to learn the properties of a GUI object on which operation is
performed.

 During Run-Time, UFT compares the stored object properties with actual properties
of the object available on screen and uniquely identifies an object independent of its
location on a screen.

 The stored object and together with its properties is called TEST Object.

 During Run-Time, the actual object available on the application under test is called
Run-Time Object.

 QTP stores Object and its properties in the Object Repository to identify them during
run-time. An Object could have a large number of properties associated with it. For
example, in Web Environment, a Button could have the following properties
associated.

 If QTP will try and remember all the available properties for an object, size of Object
Repository will bloat and script execution time will increase drastically.
 To avoid this, QTP by default does not store all the properties of an object but a
limited no. of typical properties for an object which helps in its unique identification.
 This choice of properties(to be saved during record time) for various environments
and objects is stored in Object Identification.

Object Description, Mandatory & Assistive Properties:


 An object property and its value are called Object Description. The Object
Description is used to uniquely identify the corresponding Object.

 For example, for a WebButton property “name” and its value “Login” together can
be termed as Object Description for that Web Button.

 To access, In QTP in Tools Menu, select Object Identification. In Object Recognition


Dialog Box you can see a drop down of all the environments installed and loaded.

 You can select an environment and QTP auto-populates list of all the supported
objects belonging to that environment. On the right QTP lists the properties that will
be stored for the object. The list is divided into:

i. Mandatory Properties: The main and core object properties of the object.

ii. Assistive Properties: The optional properties that are recorded only when
UFT is unable to create a unique object description using mandatory
properties alone.
 QTP will store a value of alt, HTML tag, image type, properties mandatory even if it
can uniquely identify it using the alt property alone.

 In case it cannot create unique description using mandatory property, QTP will store
assistive property. In this case, QTP will store the class property.

 If this property helps create a unique description of the object, QTP will not store the
file name, height property. If a class property is not sufficient to create a unique
description, QTP will store filename property. If filename property creates a unique
description QTP will not store height property and so on.

 Suppose during Record Time, QTP has only stored class property. At Runtime, QTP
will forget the distinction between mandatory and assistive properties and compare
all the recorded properties.

 Even if any one of the properties does not match its stored value, Script fails.
SMART IDENTIFICATION IN
QTP / UFT

 If the usual object identification process fails, UFT triggers Smart Identification,
which is a more flexible mechanism for identifying objects provided it is enabled in
Object Identification settings.

 Smart Identification uses two categories of properties:

i. Base Filter Properties: It contains the most fundamental properties of a


particular test object class; those whose values cannot be changed without
changing the essence of the original object.

ii. Optional Filter Properties: Other properties that can help identify objects.

Enabling Smart Identification for an Object:


 Navigate to "Tools" → "Object Identification". Object Identification dialog opens.

 Choose the Environment, Object Class and Turn ON "Enable Smart Identification" as
shown below:
 Click Configure and choose the base and Optional Filter Properties.

 Add Properties in Base Properties apart from the default one and also add/remove
Optional Filter Properties. Please note that same properties cannot be a part of both
Mandatory and Assistive Properties and click "OK".

 Verify if the Smart Identification is enabled after adding object of that type in the
Object Repository. Smart Identification is set to TRUE. We can also make it False in
case we do not want to enable Smart Identification.
 We can even disable a test Level by applying at test script level under "Settings" of
"File" Menu as shown below:

 If the Smart Identification is disabled as per Step# 6 then it will not apply smart
identification for any object during the script execution.

 In case the objects are added with Smart Identification as Off, QTP will not use Smart
Identification for recognizing in future, even though we have enabled it later.
ORDINAL IDENTIFIER IN QTP /
UFT
 If mandatory and assistive properties are insufficient to identify an object during a
record session, QTP uses Ordinal Identifier in addition to other captured properties
to identify the objects during a record session.

 By default, an ordinal identifier type exists for each test object class.

 In the Object Identification Window, you can modify the default Ordinal Identifier for
an Object

 There three types of Ordinal Identifiers in HP UFT:


i. Index Based
ii. Location Based
iii. Creation Time

1. Index Based:

 When using Index based ordinal identifier, while recording, QTP will
assign a value to INDEX property of an object.

 The value is based on the order in which the object appears within the
source code.

 The first occurrence has value 0.

 Index property values are object-specific.

 Therefore, if you use Index:=3 to describe a WebEdit test object,


Quick Test searches for the fourth WebEdit object on the page.
 An object appearing first in the page/Window will have a smaller
Index value when compared to another object that comes later in the
same page/Window.

Object Name Index Value

TextBox 1 0

TextBox 4 1

TextBox 2 2

TextBox 5 3

TextBox 3 4

TextBox 6 5

2. Location Based:

 When using location based ordinal identifier, while recording, Micro


Focus UFT will assign a value to LOCATION property of an object to
uniquely identify the object.

 The value is based on the order in which the object appears within the
window, frame, or dialog box, in relation to other objects with
identical properties.
 The first occurrence of the object is 0.

 Values are assigned in columns from top to bottom and left to right.

3. Creation Time:

 When using the creation time ordinal identifier, while recording, QTP
will assign a value to Creation Time property of a Web Browser.

 The Identifier is only available for the Web Environment.

 This value indicates the order in which the browser was opened
relative to other open browsers.

 The first browser that opens while recording receives the value
CreationTime=0 and succeeding browsers are given values 1, 2, 3 …
and so on.

'Sync's www.google.com
Browser("creationtime:=" ).Sync

'Gets the RO text property of www.yahoo.com


Browser("creationtime:=1").GetROProperty("text")

'Highlights microsoft.com
Browser("creationtime:=2").Highlight
ACTIONS IN QTP/UFT
 Actions helps testers to divide scripts into groups of QTP statements .

 Actions are similar to functions in VBScript; however, there are a few differences.

 The properties of the action can be accessed by right clicking on the Script Editor
Window and selecting "Properties".

 Action properties contains the following information:


i. Action Name
ii. Location
iii. Reusable Flag
iv. Input Parameters
v. Output Parameters

Types of Actions:
 Non – Reusable Action: An action that can be called only in that specific test in
which it has been designed and can be called only once.

 Reusable Action: An action that can be called multiple times, any test in which it
resides, and can also be used by any other tests.
Working with Actions:
 There are three options to insert an action:
i. Call to New Action
ii. Call to Copy of Action
iii. Call to Existing Action

1. Call to New Action:

 Testers can insert a new action at any point of the script by


performing the following steps:

 Right click on the scripting area and select "Call to New Action".

 In the "Insert Call to New Action" Window, give the test name,
description, and also specify if it is a reusable action or not. Most
importantly, select the location of the action to be inserted.
 You can check the changes, graphically, in the test Name Tab as
shown below:

2. Call to Copy of an Action:

 Testers can insert a copy of an existing action at any point of the script
by performing the following steps:

 Right click on the scripting area and select "Call to Copy of Action".
 In the "Insert Call to Copy of Action" Window, Select "Test Name",
"Action Name" and also select the location of the action to be
inserted.

 Immediately, the script is auto-generated to show that the copy of an


action is inserted.

RunAction "Copy of Calculate", oneIteration


 You can check the changes graphically in the test Name Tab as shown
below:

3. Call to Existing Action:

 Testers can insert an Existing action at any point of the script by


performing the following steps:

 Right click on the Scripting area and select "Call to Existing Action"
 In the "Select Action" Window, give the test name, Action name,
description and also specify the location of the action to be inserted.

 Once inserted, the following script is generated exactly at the location


where the action was inserted.

RunAction "Action1", oneIteration

 You can check the changes graphically in the test Name Tab as shown
below:
TYPES OF RECORDING MODES
IN QTP/UFT
 HP UFT (QTP) supports 4 types of recording modes:
i. Normal Recording
ii. Analog Recording
iii. Low-level Recording
iv. Insight Recording

1. Normal Recording:

 This is the default Recording mode that records the objects and the
operations performed on the application under test.

 It is the default mode of recording which takes full advantage of Quick


Test Professional’s test object model.

 It recognizes objects in the application regardless of their location on


the screen.

2. Analog Recording:

 In an analog recording mode, Quick Test Professional records and


tracks every movement of the mouse as you drag the mouse around a
screen or window.

 Micro Focus UFT’s Analog recording is captured as Tracks and stored


in the directory of your test.

 It is useful for recording operations that cannot be recorded at the


level of an object. Eg., A signature produced by dragging the mouse

3. Low – Level Recording:

 This mode enables you to record on any object in your application,


irrespective of QTP recognizes the specific object or the specific
operation.
 It is used when the exact coordinates of the object are important for
your tests. A good example would be hashmaps where clicking
different sections of a picture take you to different links.

 Used when recording tests in an environment (or on an object) not


recognized by QTP.

 Low-level mode records the x,y coordinates of any clicks.

4. Insight Recording:

 UFT records operations, based on its appearance and not based on its
native properties.
FUNCTIONS IN QTP / UFT
 If you have segments of code that you need to use several times in your tests, you
may want to create a user-defined function.

 By using user-defined functions, your tests are shorter, and easier to design, read,
and maintain.

 Your own function libraries in Micro Focus UFT can contain VBScript functions,
subroutines, modules etc.

Steps to create Functions:


 To create a new function library in HP QTP. Select File > New > Function Library. It
opens as a new tab in QTP.

Function Demo

MsgBox "This is a Test Function"

End Function

 A function has an extension .qfl

 Associate the library with your test. Click File > Settings > Resources > Associate
Function Library.Click Add. Select The Function Library File. Click Okay

 Last step to call the function in your test script.


STEP GENERATOR IN QTP / UFT
 The Step Generator is a utility in UFT that could be utilized to add test steps in a Test
without writing the code manually.

 You can use the Step Generator from the Keyword View and also from the Editor.

 To launch Step Generator, navigate to Design -> Step Generator.

 The Step Generator utility provides options to define steps for the following three
categories namely:
i. Test Objects
ii. Utility Objects
iii. Functions

1. Step Generation using Test Objects:

 It is used to generate test steps using the test objects present in the
Object Repository.

 Step Generator also gives you the option to select the object from the
application if the same is not available in the object repository.
 If the required Test Object is not available in the Object drop-down,
click on the pointing hand icon as shown above. “Select Test Object”
window will be displayed with the Object tree to let you select the
required object.

 If the required object is not available in the object repository click on


the cube icon button with a pointing hand to select an object from the
application itself. Select the required object from the object tree and
click on the “OK” button.
 Now you have to select the operation you want to perform on the
selected object. Click on the Operation drop-down, it will display a list
of all the methods that can be performed on the object.

 I have selected an object “userName” that is a WebEdit box. In order


to show you an example, I have selected Set operation to set the text
on it. After selecting the operation, you will see all the associated
parameters with the method listed under the Arguments section.
 You can add a constant value to the argument by clicking on the value
column and manually set the value. The generated code is displayed
under the Generated Step section.

 Click on the “OK” button. The generated step will be added to the
current action of the Test.

Browser("Mercury Tours").Page("Mercury
Tours").WebEdit("userName").Set "TestUser1"

 You can also parametrize the value rather than setting a constant
value. Click on the <#> icon next to the value column or press
Ctrl+F11. The Value Configuration Options window will be displayed.
You can parametrize the constant value with either DataTable or
Environment value.
 To parameterize the value with DataTable, select the DataTable
option, and enter the name of the parameter and click on the “OK”
button.

 The parameter name will be displayed in the value field.


2. Step Generator using Utility Objects:

 This category can be used to generate steps for various utility objects
as shown below.
 Let’s say, we have added a parameter UserName in the global sheet
of the DataTable and want to retrieve its value at runtime in UFT.

 Select the DataTable object and provide the name of the ParameterID
and SheetID as shown below.
SYNCHRONISATION IN QTP /
UFT
 Synchronization is used to match the speed of UFT test script execution with the
speed of the application under test.

 UFT test can be synchronized in the following way:

i. Wait Statement - Wait is used when we want UFT to wait for the specified
time. Once the specified time is lapsed, UFT process with execution of the
next step.

Syntax – Wait (seconds)


Example – Wait(5)

ii. WaitProperty Statement - WaitProperty is used to wait until the given object
property achieves the specified value in the given timeout else it continues to
the next step.

Syntax – object.WaitProperty(PropertyName, PropertyValue, [TimeOut])

iii. Sync Statement (Only for Web) - Sync statement Waits for the browser to
complete current navigation.

Syntax – BrowserObject.Sync
TRANSACTIONS IN QTP / UFT
 Transactions in UFT can be used to measure how long does it take to execute a
section or a few steps of your test.

 You define transactions within your test by enclosing the appropriate sections of the
test with start and end transaction statements.

 Transactions can be inserted anywhere in the script. There is no limit to the number
of transactions that can be added to a test.

 You can also insert a transaction within a transaction.

Steps to add Transactions:


 In QTP, select the appropriate state where you want to start your transaction.

 Select Insert Start Transaction from Design -> Start Transaction. Start Transaction
Dialog Box opens. The Start Transaction Dialog box will be displayed. In the Name
field, you will have to provide a valid name and click on the OK button.

 The Start Transaction statement will be added at the line where the cursor was
placed before.

 In the same fashion, we can add the End Transaction. Set the cursor at line number
and select “Design ->EndTransaction”. End Transaction dialog box will be displayed
with the name what we provided for start transaction. Click on the OK button.
 The End Transaction will be added to the script as shown below.

 Run your Test Script and open the test result. You can see all Start and End
Transactions in the result viewer. Upon clicking on the End Transaction it will show
how long it has taken to execute the code for the specific section of the code. Here
we can see that for LoginTransaction it took around 5.6323 seconds.
ENVIRONMENT VARIABLES IN
QTP / UFT
 Environment variables are variables that describe the environment in which
programs run.

 Environment variables are dynamic in nature, and it can be changed. There are a
number of environment variables that can be referenced by programs and can be
useful in finding information about their computing environment.

 Micro Focus UFT environment variables can be accessed by all actions, function
library, and recovery scenarios.

Types of Environment Variables:


 Environment variables are those variables that can be used globally in the tests.
There are two types of environment variables:
i. Built-in Variables
ii. User-defined Variables.

1. Built-in Variables:

 In QTP, built-in variables are pre-defined variables. It enables the user


to retrieve the information about the test that is executing and to get
information about the O.S (Operating Systems) on which the test is
executing.

 Some of the built-in variables are Action iteration, Operating system,


Test directory, local hostnames, Operating system version etc.

 Go to file -> Settings -> Environment tab to view the environment


variable section to see the list of environmental variables.
 The values from environment variables can be obtained and used
wherever necessary during the run session. MsgBox
Environment.Value(“OSVersion”)

2. User – defined Variables:

 Before the execution of the test, these are the variables that are
defined by the user. It can be used globally across different tests, or
they can also be restricted to one test.

 User-defined variables were classified into two types:

 Internal
 External
 User defined – Internal Variables: These variables are defined by the user before
executing the test and these are available only to a particular test.

 User defined- External Variables: These variables are defined by the user and it can
be used globally across different tests.

MsgBox Environment.Value(“Guru99”)
DEBUGGING IN UFT / QTP
 Debugging, in automation testing context, is a systematic process of spotting and
fixing the coding issues in the automation script so that the script will be more
robust and can spot the defects in the application.

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.
VB SCRIPT VARIABLES
 A variable is a named memory location used to hold a value that can be changed
during the script execution.

 VBScript has only ONE fundamental data type, Variant.

 Variables are declared using “dim” keyword. Since there is only ONE fundamental
data type, all the declared variables are variant by default. Hence, a user NEED NOT
mention the type of data during declaration.

Datatypes in VB Script:
 Empty
 Null
 Integer
 Long
 Single
 Double
 Currency
 Date
 String
 Object

Option Explicit:
 The Option Explicit statement forces the explicit declaration of all variables using the
Dim, Private, Public, or ReDim statements.

 If we use Option Explicit and if we don't declare the variables then the interpreter
will throw and error.

Arrays in VB Script:
 An Array is a variable having named memory location which serves as a Container
and can hold multiple values in a single location.

'Method 1 : Using Dim


Dim arr1() 'Without Size

'Method 2 : Mentioning the Size


Dim arr2(5) 'Declared with size of 5

'Method 3 : using 'Array' Parameter

Dim arr3
arr3 = Array("apple","Orange","Grapes"

Multi – Dimensional Array:

 Dim Array1(1,1)

Redim Statement:

 Redim Statement is used to re-define the size of an Array. When the array is
declared without any size, then it can be declared again using Redim with the
feasibility of specifying the size of an array.

Preserve Keyword:

 Preserve keyword is used to preserve the contents of a current array when the size
of an array gets changed.

Msgbox in VB Script:

 The MsgBox function displays a message box and waits for the user to click a button
and then an action is performed based on the button clicked by the user.

 Syntax:

MsgBox(prompt[,buttons][,title][,helpfile,context])

 Prompt − A Required Parameter.


 buttons − An Optional Parameter. A Numeric expression that specifies
the type of buttons to display, the icon style to use, the identity of the
default button, and the modality of the message box.

You might also like