QTP Complete Notes
QTP Complete Notes
QTP Complete Notes
QTP stands for QuickTest Professional, a product of Hewlett Packard (HP). This tool helps testers
to perform an automated functional testing seamlessly, without monitoring, once script
development is complete.
HP QTP uses Visual Basic Scripting (VBScript) for automating the applications. The Scripting
Engine need not be installed exclusively, as it is available as a part of the Windows OS. The
Current version of VBScript is 5.8, which is available as a part of Win 7. VBScript is NOT an
object-oriented language but an object-based language.
Testing Tools
Tools from a software testing context, can be defined as a product that supports one or more test
activities right from planning, requirements, creating a build, test execution, defect logging and
test analysis.
Classification of Tools
Tools can be classified based on several parameters. It includes −
Types of Tools
Sr.No. Tool Type Used for Used by
Version History
Now let us take a look at the version history of QTP.
Versions Timelines
Astra Quick Test v1.0 to v5.5 - Mercury Interactive May 1998 to Aug 2001
QuickTest Professional v6.5 to v9.0 - Mercury Interactive Sep 2003 to Apr 2006
Readily Integrated with Test Management Tool (Hp-ALM) which enables easy scheduling and
monitoring.
Since it is an HP product, full support is provided by HP and by its forums for addressing technical
issues.
Disadvantages
Unlike Selenium, QTP works in Windows operating system only.
Not all versions of Browsers are supported and the testers need to wait for the patch to be released
for each one of the major versions.
Having said, that it is a commercial tool, the licensing cost is very high.
Even though scripting time is less, the execution time is relatively higher as it puts load on the CPU &
RAM.
For any automated tool implementation, the following are the phases/stages of it. Each one of the
stages corresponds to a particular activity and each phase has a definite outcome.
Test Automation Feasibility Analysis − First step is to check if the application can be automated
or not. Not all applications can be automated due to its limitations.
Appropriate Tool Selection − The next most important step is the selection of tools. It depends on
the technology in which the application is built, its features and usage.
Evaluate the suitable framework − Upon selecting the tool, the next activity is to select a suitable
framework. There are various kinds of frameworks and each framework has its own significance. We
will deal with frameworks in detail later in this tutorial.
Build Proof of Concept − Proof of Concept (POC) is developed with an end-to-end scenario to
evaluate if the tool can support the automation of the application. It is performed with an end-to-end
scenario, which ensures that the major functionalities can be automated.
Develop Automation Framework − After building the POC, framework development is carried out,
which is a crucial step for the success of any test automation project. Framework should be built after
diligent analysis of the technology used by the application and also its key features.
Develop Test Script, Execute, and Analyze − Once Script development is completed, the scripts
are executed, results are analyzed and defects are logged, if any. The Test Scripts are usually version
controlled.
Step 2 − The license page appears. You can click Continue as we have installed the trial
license.
Step 3 − The Add-ins dialog box opens for the user to select the required add-ins.
Note − Do not load all the add-ins but just the required add-ins and click OK.
Step 4 − After loading the required add-ins, the UFT 11.5 tool opens for the user and the
first glimpse of the UFT looks, as shown below −
Recording a test corresponds to recording the user actions of the application under test so that
UFT automatically generates the scripts that can be played back. Record and Playback can give us
the first impression of the tool, whether it can support the technology or not, if the initial settings
are done correctly.
Steps for Record and Playback are as follows −
Step 1 − Click "New" test from the Start Page as shown below −
Step 2 − Clicking "New" Link, a new test window opens and the user needs to select the test
type. Select "GUI Test", give a name for the test and the location where it needs to be saved.
Step 3 − Once a New test is created, the new test screen opens as shown below. Now, click the
"Action1" tab, which is created with 1 action by default.
Step 4 − Click the "Record" Menu and select "Record and Run Settings" as shown below −
Step 5 − The Record and Run Settings dialog box opens and based on the type of application, one
can select Web, Java, or Windows Applications. For Example, here, we will record a Web Based
Application (http://easycalculation.com/).
Step 6− Click Record. The Internet Explorer opens automatically with the web
address https://www.easycalculation.com/ as per the settings. Click the "Numbers" link under
"Algebra" and key in a number and hit "Calculate". After completion of the action, click the "Stop"
button in the record panel. You will notice that the script is generated as shown below −
Step 7 − Now playback the script by clicking the playback button. The Script replays and the
result is displayed.
Step 8 − The result window is opened, by default, which exactly shows the timestamp of
execution, pass and failed steps.
It is used as the preliminary investigation method to verify if UFT can support the
technology/application.
Used to create a test a basic functionality of an application or feature that does not require
long-term maintenance.
It can be used for recording both mouse movements and keyboard inputs.
Modes of Recording
Normal Recording − This is the default Recording mode that records the objects and the
operations performed on the application under test.
Analog Recording − This records not only the keyboard actions but also the mouse
movements relative to the screen or the application window.
Low-Level Recording − This records the exact co-ordinates of the objects independent of
the fact whether UFT recognizes the object or NOT. It just records the co-ordinates, hence
does NOT record mouse movements.
Insight Recording − UFT records operations, based on its appearance and not based on
its native properties.
How to Choose Recording Modes
After clicking the Recording button, the user can choose the recording mode from the recording
pane that appears on the screen, once the recording starts. The selection can be made from any
of the ones that has been discussed above.
You will see that the following scenario is recorded in all the modes and the same action has been
recorded under various circumstances.
Launch IE - https://www.easycalculation.com/
Hit Calculate
Script Recorded under Default, Analog and Low Level recording mode is given below −
Desktop.RunAnalog "Track1"
Object Repository
Object Repository is a collection of object and properties with which QTP will be able to recognize
the objects and act on it. When a user records a test, the objects and its properties are captured
by default. Without understanding objects and its properties, QTP will NOT be able to play back
the scripts.
1 Object Spy and its Features : - To understand the usage of object spy and its
associated functionalities.
2 Working with Object Repository: - Adding, editing, deleting objects from an Object
Repository and its associated functionalities.
3 Types of Object Repository : -Deals with shared Object and local Object Repository and
their context with respect to scripting.
4 User-defined Objects : - Deals with the circumstances to use the User-Defined Objects.
5 Object Repository in XML : - Deals with converting OR's to XML and using the object
Repository as XML.
7 Ordinal Identifiers : - Circumstances where the ordinal identifiers are used and its
advantages.
Step 1 − Clicking the Object Spy icon, the Object Spy Dialog box opens. The Objects can be
added to the repository on clicking the pointing hand.
Step 2 − 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.
Step 3 − After Spying an object, click the "Highlight" option to highlight the object in the
application.
Step 4 − For adding the object into the Object Repository, click the "Add objects" button in the
Object spy dialog.
Step 5 − 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.
Step 6 − 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 −
Even when a user does a recording, the objects and its properties are captured automatically.
Hence, we are able to replay the script successfully.
Step 2 − One can add the properties additionally apart from the default ones by clicking the "+"
button and remove it using the "x" button. If we want to restore the defaults, we can click on the
"circular arrow" button.
Step 3 − One can change the object's name. Here the name of the object is "Numbers" that can
be renamed to "num", which will not have any effect on identifying the object uniquely. If there is
a change in logical name, the same name should be used while scripting. Only the Object's Name
can be changed and not its properties.
Note − Properties of any object must be unique so that QTP will be able to recognize the objects
and act on it. If the object properties were same for two or more objects, then during execution
an error would be thrown that "More than one object is matched for the specified properties".
Step 4 − After adding the objects, the same can be used in script by simple drag-drop as shown
in the figure. When the object is dragged and dropped, the default operation is set. For example,
click for a button, Set for a Text Box etc.
QTP - Object Repository Types
Object Repository is of two types.
This Object Repository is available; one for This type of OR is available for multiple tests
each action. and for multiple actions.
This is the OR that is available for each tests, This type of OR is usually used in frameworks
by default. considering reusability and maintainability.
It is NOT a standalone file that can edited. SOR is a standalone file that can be edited
easily.
It should be used when not many tests are SOR Should be used when there are different
working on the same screens of the scripts interacting with the same type of the
application under test. object.
In the following example, an object of a specific class is made to recognize as an object of Type
"button". Hence, this object inherits all properties of a button and we can use the objects that are
supported by button.
These tools help us largely to spot the differences in the Object Repository
Step 3 − The Object Repository comparison Window opens and the user needs to select the two
Object Repository files to be compared.
Step 4 − It performs the comparison and displays the differences one by one as shown below −
Step 5 − It can be filtered based on three parameters viz - unique objects, identical objects,
partial match objects.
Merging Option is a great boon for testers who need to merge two-object repository without losing
the object hierarchy.
Steps to Merge OR's
Step 1 − Navigate to "Resources" >> "Object Repository Manager"
Step 3 − The Object Repository Merge window opens and the user needs to select the two Object
Repository files to be merged.
Step 5 − It can be filtered based on two parameters viz - show all objects, show only conflicting
objects.
QTP - Ordinal Identifiers
An Ordinal Identifier assigns a numerical value to the test objects, which indicates its location or
order relative to its group. The Ordered value enables QTP to recognize it uniquely when the
inbuilt properties are NOT sufficient to do so.
There are three Ordinal Identifiers in QTP that can be used in different context −
Index
Location
Creation Time
Index
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.
The value of index for the group of text boxes will be as follows –
TextBox 1 0
TextBox 4 1
TextBox 2 2
TextBox 5 3
TextBox 3 4
TextBox 6 5
Location
The Location property works vertically from top to bottom and from left to right. Hence, for the
same case, the value of location for the group of text boxes will be as follows −
Object Name Index Value
TextBox 1 0
TextBox 2 1
TextBox 3 2
TextBox 4 3
TextBox 5 4
TextBox 6 5
Creation Time
The Creation Time property holds good only for web based application. When we open two
browser sessions of the same website, QTP will not be able to recognize the window, as both the
windows will have the same set of properties. Hence, we can use creation time with which QTP will
be able to act on the window.
Hence, to work on a specific browser, we need to explicitly mention the Creation time in OR or we
can use the description of objects, which we will see in detail in descriptive programming section.
'Sync's www.google.com
Browser("creationtime:=" ).Sync
'Highlights microsoft.com
Browser("creationtime:=2").Highlight
In these circumstances, if we want to work on the child objects, we need to use description of
objects using which we will be able to work on all the objects in a particular window/page.
Descriptive programming will be dealt in detail in the upcoming chapter but the significance of this
chapter is to understand child objects and its usage.
The following Script gets the name of the links from the website "www.easycalculation.com"
Dim oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Link"
Dim i
'obj.Count value has the number of links in the page
For i = 0 to obj.Count - 1
'get the name of all the links in the page
x = obj(i).GetROProperty("innerhtml")
print x
Next
QTP - Actions
Actions helps testers to divide scripts into groups of QTP statements. Actions are similar to
functions in VBScript; however, there are a few differences. By default, QTP creates a test with
one action.
Actions Functions
Action is an in-built feature of QTP. VBScript Functions are supported by both VBScript
and QTP.
Actions parameters are passed by value Function parameters are passed either by by value or
only. by ref.
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 −
Action Name
Location
Reusable Flag
Input Parameters
Output Parameters
Types of Actions
There are three 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.
External Reusable action − It is a reusable action stored in another test. External actions are read-
only in the calling test, but it can be used locally with the editable copy of the Data Table information
for the external action.
Working with Actions
There are three options to insert an action. Click on each one of those to know more about the
selected type of action.
Sr.No. Action Type & Description
1 Insert Call to New Action :- Inserts a New Action from the existing action
Step 1 − Right click on the scripting area and select "Call to New Action".
Step 2 − 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.
Step 3 − You can check the changes, graphically, in the test Name Tab as shown below −
You can also use QTP commands to call the Action at any point in the script.
Step 1 − Right click on the scripting area and select "Call to Copy of Action"
Step 2 − 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.
Step 3 − Immediately, the script is auto-generated to show that the copy of an action is inserted.
Step 4 − You can check the changes graphically in the test Name Tab as shown below −
QTP - Call to Existing Action
Inserting call to Existing Action
Testers can insert an Existing action at any point of the script by performing the following steps −
Step 1 − Right click on the Scripting area and select "Call to Existing Action"
Step 2 − In the "Select Action" Window, give the test name, Action name, description and also
specify the location of the action to be inserted.
Step 3 − Once inserted, the following script is generated exactly at the location where the action
was inserted.
Step 4 − You can check the changes graphically in the test Name Tab as shown below −
QTP - Datatables
A DataTable, similar to Microsoft Excel, helps the testers to create data-driven test cases that can
be used to run an Action multiple times. There are two types of Datatables −
Local DataTable − Each action has its own private datatable, also known as local datatable, which is
can also be accessed across actions.
Global DataTable − Each test has one global data sheet that is accessible across actions.
The data sheet can be accessed from the "Data" Tab of QTP as shown below −
To execute a test case for some specified number of iterations, one can set the iterations of global
datatable in the Test Settings dialog, that can be accessed using File → Settings → Run(Tab) as
shown below −
Example
For example, if a user wants to parameterize "compound Interest" of http://easycalculation.com/ that can be
1 Data Table Methods : Gives detailed information about the data table methods.
3 DTSheet Object Methods : -Gives detailed information about the DTSheet methods.
GlobalSheet Returns the first sheet of the run-time data table. DataTable.GlobalSheet
LocalSheet Returns the Active local sheet of the run-time data table. DataTable.LocalSheet
Value Retrieves the value of the cell in the specified parameter. DataTable.Value(Paramet
erID, [SheetID])
Example
Consider the following DataTable −
colcount = DataTable.GetSheet("Global").GetParameterCount
msgbox colcount ' Displays 3
DataTable.SetCurrentRow(2)
val_rate = DataTable.Value("Rate","Global")
print val_rate ' Displays 7%
val_ppl = DataTable.Value("Principal","Global")
print val_ppl ' Displays 2556
val_Time = DataTable.Value("Time","Global")
print val_Time ' Displays 5
QTP - DTParameter Object Properties
Method Description Syntax
Name
Example
Consider the following DataTable –
Val = DataTable.GetSheet("Global").GetParameter("Principal").ValueByRow(2)
print Val ' Val Displays 2556
DataTable.SetCurrentRow(1)
Val1 = DataTable.GetSheet("Global").GetParameter("Principal").Value
print Val1 ' Val1 displays 232
Example
'Accessing Datatable to get Row Count and Column Count
rowcount = DataTable.GetSheet("Global").GetRowCount
msgbox rowcount ' Displays 4
colcount = DataTable.GetSheet("Global").GetParameterCount
msgbox colcount ' Displays 3
DataTable.SetCurrentRow(2)
val_rate = DataTable.Value("Rate","Global")
print val_rate ' Displays 7%
val_ppl = DataTable.Value("Principal","Global")
print val_ppl ' Displays 2556
val_Time = DataTable.Value("Time","Global")
print val_Time ' Displays 5
QTP - CheckPoints
Checkpoints, as the name says it all, refer to a validation point that compares the current value of
specified properties or current state of an object with the expected value, which can be inserted at
any point of time in the script.
Types of Checkpoints
Sr.No. Type & Description
1 Standard Checkpoint: -Verifies the property values of an object in application under test and
supported by all add-in environments.
3 File Content Checkpoint : -Verifies the text in a dynamically generated or accessed file such
as .txt,.pdf
4 Table Checkpoint : -Verifies the information within a table. Not all environments are
supported.
5 Text Checkpoint : -Verify if the text that is displayed within a defined area in a Windows-based
application, according to specified criteria.
6 Text Area Checkpoint : -Verifies if the text string is displayed within a defined area in a
Windows-based application, according to specified criteria.
7 Accessibility Checkpoint:- Verifies the page and reports the areas of the Web site that may
not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines
8 Page Checkpoint : -Verifies the characteristics of a Web page. It can also check for broken
links.
9 Database Checkpoint :- Verifies the contents of a database accessed by the application under
test.
10 XML Checkpoint : -Verifies the content of the .xml documents or .xml documents in Web pages
and frames.
Inserting CheckPoint
When the user wants to insert a checkpoint, one has to ensure that most of the checkpoints are supported during the
recording sessions only. Once the user stops recording, checkpoints are not enabled.
Given below is the checkpoint menu, when the user is NOT in the recording mode.
Given below is the checkpoint menu, when the user is in the recording mode.
Example
The checkpoints are added for the application under test - "http://easycalculation.com/"
If Status Then
print "Checkpoint Passed"
Else
Print "Checkpoint Failed"
End if
If imgchkpoint Then
print "Checkpoint Passed"
Else
Print "Checkpoint Failed"
End if
You can locate the same checkpoints in object repository, as well, as shown below. It exactly
shows what type of checkpoint is used and what are the expected values, and time out values.
QTP - Synchronization
Synchronization point is the time interface between Tool and Application under test.
Synchronization point is a feature to specify the delay time between two steps of the test script.
For example, clicking on a link may load the page is 1 second, sometimes 5 seconds or even it
may take 10 seconds to load it completely. It depends on various factors such as the application-
server response time, network bandwidth, and client system capabilities.
If the time is varying then the script will fail, unless the tester handles these time differences
intelligently.
Exist
Wait
Let us say, we need to insert a sync point between clicking on "numbers" link and clicking on
"simple Interest" calculator in "www.easycalculation.com". We will now take a look at all the five
ways to insert sync point for the above scenario.
Method 1 − WaitProperty
WaitProperty is a method that takes the property name, Value and Timeout value as input to
perform the sync. It is a dynamic wait and hence, this option is encouraged.
Method 2 − Exist
Exist is a method that takes the Timeout value as input to perform the sync. Again, it is a dynamic
wait and hence this option is encouraged.
Else
Print "Link NOT Available"
End IF
Method 3 − Wait
Wait is a hardcoded sync point, which waits independent of the event happened or NOT. Hence,
usage of Wait is discouraged and can be used for shorter wait time such as 1 or 2 seconds.
' Method 4 :
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
Browser("Math Calculator").Sync
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").Click
Step 3 − We need to select the object, which we want to be the Sync Point. After selecting the
object, object window opens as shown below −
Step 4 − Click OK; the "Add Synchronization Window" opens. Select the Property, Value and Time
out value and click OK as shown below −
Step 5 − The script would be generated as shown below, which is the same as that of the
WaitProperty(Method 1) that we had already discussed −
Default Synchronization
When the user has not used any of the above sync methods, still QTP has an in-built Object
synchronization timeout which can be adjusted by the user.
Navigate to "File" >> "Settings" >> Run Tab >> Object Synchronization Time out as shown
below.
QTP - Smart Identification
QTP is unable to find any object that matches the recognized object description or it may find
more than one object that fits the description, then QTP ignores the recognized description and
uses the Smart Identification mechanism to recognize the object.
Base Filter Properties − The basic properties of a particular test object class whose values cannot
be changed without changing the essence of the original object.
Optional Filter Properties − Other properties also assist in identifying the objects of a particular
class whose properties are unlikely to change often but can be ignored if they are no longer
applicable.
Step 2 − Choose the Environment, Object Class and Turn ON "Enable Smart Identification" as
shown below −
Step 3 − Click Configure and choose the base and Optional Filter Properties.
Step 4 − 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".
Step 5 − 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.
Step 6 − We can even disable a test Level by applying at test script level under "Settings" of
"File" Menu as shown below −
Step 7 − If the Smart Identification is disabled as per Step# 6 then it will not apply smart
identification for any object during the script execution.
Step 8 − 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.
QTP - Debugging
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.
There are various ways to perform debugging using break points in QTP. Break points can be
inserted just by pressing "F9" or by using the Menu option "Run" → "Inserting/Removing Break
Point".
After Inserting the Break point, the "Red Colored" Dot and the line will be highlighted in RED as
shown below −
Step Into F11 Used to execute each and every Step. Steps into the Function/Action and
executes line by line. It pauses on each line after execution.
Step Over F10 Used to Step over the Function. Step Over runs only the current step in the
active document.
Step Out Shift+F11 After Step Into the function, you can use the Step Out command. Step Out
continues the run to the end of the function and then pauses the run session
at the next line.
1 F9 :-Insert/Remove BreakPoint
Output − This Tab displays all the Output of the Print Statements.
Watch − This Tab displays the Boolean output of the Given Expression.
Example
The Watch Pane shows the output expression as shown below −
The Local Variables Pane shows the values held by the local variables as shown below −