Documents null-QTP Docs
Documents null-QTP Docs
2. Software tests have to be repeated often during development cycles to ensure quality. Every time
source code is modified software tests should be repeated. For each release of the software it may be
tested on all supported operating systems and hardware configurations. Manually repeating these tests
is costly and time consuming. Once created, automated tests can be run over and over again at no
additional cost and they are much faster than manual tests.
Regression testing is testing existing software applications to make sure that a change or addition hasn’t
broken any existing functionality. Its purpose is to catch bugs that may have been accidentally
introduced into a new build or release candidate, and to ensure that previously eradicated bugs
continue to stay dead.
To perform our daily testing activities we need testing tools. Right from planning, requirements, creating
build, test execution, defect logging.
Various tools:
Test Management Tool – Plan tests, gather data from test run in different environments, log defects e.g
HP QC
Test Execution Tools: Tools like Qtp are test execution tools which help execute your code.
Performance testing tools: These measure the performance of your application in peak traffic time e.g
load runner.
QTP Stands for quick test professional, owned by HP now named as Unified Functional Testing
Advantages
Developing automated tests using VBScript doesn't require a highly skilled coder and relatively
easy when compared other object oriented programming languages.
Easy to use, ease of navigation, results validation and Report generation.
Readily Integrated with Test Management Tool(Hp-Quality Center) which enables easy
scheduling and Monitoring.
Can also be used for Mobile Application Testing.
Since it is a Hp product, the full support is provided by HP and by its forums for addressing
technical issues.
Disadvantages
Modes of recording:
Normal Mode: This is the default mode of recording; it records various objects and operations
performed on application under test.
Analog Mode: It records mouse movements relative to screen in AUT together with keyboard
movements.
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 operation based on its appearance and NOT based on its native
properties.
Q. How to select recording Modes?
When you select recording button it gives you all the above options.
The Below Scenario is recorded in all the modes and see how the same action has been recorded under
various circumstances.
Launch IE - http://easycalculation.com/
Variables in VbScript
Dim is used to declare variable sin vbscript for e.g dim avg. Here you need not declare the data
type of variable by default all variables are of variant type.
Variable Name must begin with an alphabet.
Variable names cannot exceed 255 characters.
Variables Should NOT contain a period(.)
Variable Names should be unique in the declared context.
The numeric values should be declared without double quotes.
The String values should be enclosed within doublequotes(")
Date and Time variables should be enclosed within hash symbol(#)
Variables have the following scope
Dim
Public
and private
Constants
const pi=3.14
Const myString = "VBScript"
Const myDate = #01/01/2050#
This will give an errror as value of const cannot be changed
Operators
Arithmetic operators: +, -, *, /, %, ^ (exponent)
Comparison Operators: ==, <>,>, <,>=, <=
Logical Operators AND, OR, NOT, XOR
Concatenation Operators: +, &. + is an overloaded operator here when used with strings it does
string concatenation and with numeric values it does addition.
Decision making
If statement, if..else statement, if..elseif…else, Switch / select
Select Case Utilities.Uppercase(strMenuOption)
Case "HR SYSTEM OPTIONS"
Case "STORE PARAMETERS"
End select
Loops
For..Loop – it executes the loop a given no of times
For…each Loop – for e.g
fruits is an array
fruits=Array("apple","orange","cherries")
Dim fruitnames
'iterating using For each loop.
For each item in fruits
fruitnames=fruitnames&item&vbnewline
Next
apple
orange
cherries
While Wend…loop -In a While..Wend loop, if the condition is True, all statements are executed
until Wend keyword is encountered. For e.g
A Do..Until loop is used when we want to repeat a set of statements as long as the condition is
false. The Condition may be checked at the beginning of the loop or at the end of loop.
i=10
Do Until i>15 'Condition is False.Hence loop will be executed
i=i+1
Masgbox "The value of i is:" &i
Loop
The value of i is : 11
The value of i is : 12
The value of i is : 13
The value of i is : 14
The value of i is : 15
The value of i is : 16
Dim a : a=10
For i=0 to a Step 2 'i is the counter variable and it is incremented by 2
Msgbox "The value is i is : " & i
If I = 4 Then
I = i*10 'This is executed only if i=4
Msgbox "The value is i is : " & i
Exit For 'Exited when i=4
End If
Next
The value is i is : 0,
The value is i is : 2
The value is i is : 4
The value is i is : 40
Mathemetical Functions:
Int - A Function, which returns the integer part of the given number.
Fix - A Function, which returns the integer part of the given number.
Log - A Function, which returns the natural logarithm of the given number. Negative
numbers disallowed.
Oct - A Function, which returns the Octal value of the given percentage.
Hex - A Function, which returns the Hexadecimal value of the given number.
Rnd - A Function, which returns a random number between 0 and 1.
Sgn - A Function, which returns a number corresponding to the sign of the specified
number.
Sqr - A Function, which returns the square root of the given number. Negative
numbers disallowed.
Abs - A Function, which returns the absolute value of the given number.
Exp - A Function, which returns the value of e raised to the specified number.
Sin - A Function, which returns sine value of the given numbe
Cos - A Function, which returns cosine value of the given number.
Tan - A Function, which returns tan value of the given number.
Strings:
InStr - The InStr Function returns the first occurrence of one string within
another string. The search happens from left to right.
InStr([start,]string1,string2[,compare])
Compare - 0 = vbBinaryCompare - Performs Binary Comparison(Default)
1 = vbTextCompare - Performs Text Comparison
InstrRev - Returns the first occurrence of the specified substring. Search happens from
Right to Left
Lcase - Returns the lower case of the specified string.
Ucase - Returns the Upper case of the specified string.
Left - The Left Function returns a specified number of characters from the left
side of the given input string.For e.g
Ans Mi
Right - The Right Function returns a specified number of characters from the
Right side of the given input string.For e.g
Ans pt
LTrim - The Ltrim Function removes the blank spaces that are there on the left
side of the string.
RTrim - The Rtrim Function removes the blank spaces that are there on the
Right side of the string.
Trim – The trim Function removes the blank spaces that are there on the both
sides of the string.
Len – Calculates len of string. For e.g len(“The”) = 3
Mid - The Mid Function returns a specified number of characters from a given
input string.
Mid(String,start[,Length])
var="Microsoft VBScript"
Msgbox Mid(var,2,5)
Ans “icros”
StrComp -The StrComp Function returns an integer value after comparing the two
given strings. It can return any of the three values -1, 0 or 1 based on the input strings
to be compared.
StrComp(string1,string2,compare)
MSGBOX StrComp("Microsoft","Microsoft")
MSGBOX StrComp("Microsoft","MICROSOFT")
MSGBOX StrComp("Microsoft","MiCrOsOfT")
MSGBOX StrComp("Microsoft","MiCrOsOfT",1)
MSGBOX StrComp("Microsoft","MiCrOsOfT",0)
Line 1 :0
Line 2 :1
Line 3 :1
Line 4 :0
Line 5 :1
String - The String Function fills a string with the specified character the
specified number of times.
String(number,character)
MSGBOX String(3,"$")
$$$
StrReverse - Returns a String after reversing the sequece of the characters of the
given string.
StrReverse(string)
ARRAYS:
'Method 1 : Using Dim
Dim arr1() 'Without Size
'Method 2 : Mentioning the Size
Dim arr2(5) 'Declared with size of 5
Redim Statement:
Date Functions
Date A Function, which returns the current system date
CDate A Function, which converts a given input to Date
DateAdd A Function, which returns a date to which a specified time interval has
been added
DateDiff A Function, which returns the difference between two time period
DatePart A Function, which returns a specified part of the given input date
value
DateSerial A Function, which returns a valid date for the given year,month and
date
IsDate A Function, which returns a Boolean Value whether or not the supplied
parameter is a date
Year A Function, which returns an integer that represents the year of the
specified Date
MonthName A Function, which returns Name of the particular month for the
specified date
Time Functions
Function Description
Now A Function, which returns the current system date and Time
Hour A Function, which returns and integer between 0 and 23 that represents
the Hour part of the the given time
Minute A Function, which returns and integer between 0 and 59 that
represents the Minutes part of the the given time
Timer A Function, which returns the number of seconds and milliseconds since
12:00 AM
TimeSerial A Function, which returns the time for the specific input of
hour,minute and second
Click "Trials and Demos" link and select "Hp Unified Functional Testing 11.50 CC
English SW E-Media Evaluation" as shown below:
Read the terms and conditions, Click next and start downloading
The downloaded file will be in .RAR format
Now you need to unzip the archive and the folder contents would be as shown below
and execute the Setup.exe.
Upon Executing the Setup File, inorder to install, select "Unified Functional Testing Set
up" from the list as shown below:
Once you complete your installation, the "Additional Installation Requirements" Dialog
box opens. Select everything in the list other than "Run License Installation Wizard"
and click "RUN". We Need NOT select "Run License Installation Wizard" because we are
installing the trial version which by default gives a license for 30 days.
After Installation, application can be launched from the Start Menu as shown in
The License page appears. You can click on continue as we have installed the
trial license
The Addins Dialog box opens for the user to select the required addins' DONOT
load all the addin's but just the required addins and click "Ok" button
QTP Record And playback
Upon Clicking, "New" Link, the new test window opens and the user need to
select the test type. Select "GUI Test", give a name for the test and also the
location where it needs to be saved.
Now click on Record button and select record and run settings, the record and run
settings dialog appears. Based on the type of application, one can select i.e Web, Java,
Windows Applications.
Note: - The no of addins you have installed that many no of tabs will appear in record
and play back window.
For e.g we will take flight application which comes with QTP and enter agent name and
password on the login screen.
The following screen shows the keyword view. As you can see the actions are in form
of a table with columns: Item, operation, value and documentation.
The corresponding keyword view for the above test will look like.
Actions
All tests in QTP are basically composed of actions. Each actions is nothing but a
sequence of statements performing a sequence of actions (activities). Actions make
your test look modular.
For e.g. if someone has to send a mail, he will login into his Gmail account, compose
mail, send and logout. These can be three actions although they can be written in one
action.
If they all are written together the lines of code will be large and difficult to mainatian,
hence it is better to divide it into actions. The test is essentially call to action 1, call to
action 2, call to action 3 and so on.
In the above dropdown you can click and view all the actions associated with the test
Here we can also select and go to that particular action, view and edit.
There is also a concept of re-usable actions, these actions can be reused multiple
times within the test they were created or by other tests also. By default each action is
reusable although that can be changed if needed.
Object Hierarchy- Qtp uses a tree hierarchy to store and recognize objects. In our
case agent name and password are child objects to the container object login which is
a dialog. Container objects are window, dialog in windows environment and browser
and page in web environment.
Iten: Each step is a sequence of events performed on an item, item can be one of the
following:
a. Test Object e.g Agent name
b. Utility object like datatable object
c. Statements like loops
d. Function call
Operation: It shows the operation that is performed on the item. When this column is
clicked for a particular item it lists all the available operations that can be performed on
the object.
Comments: The tester can write anything under this column. It will be treated as
comments in the expert view.
Obect Repository:
Click the icon or click Tools -> Object Spy to access the object repository
The spy not only displays the properties, it also has a provision that lets the users add a
certain object to the OR. You can do that by clicking on the OR icon with a + in it.
Object Repository
It stores the set of properties that uniquely identifies the Object (description) and also
names the object for the sake of identification in our test, based on its most prominent
feature.
The objects that are acted upon during record process get automatically added to the OR.
You can also use Ctrl + R to invoke Object repository.
There are two kinds of Object repositories
a. Shared repository
b. Local repository
If a local as well as shared repository has an object with same name the test will use a
local object first.
There can be more than one Shared OR’s associated to the same action. If Shared OR1
and Shared OR2 have one object named OBJ1 each and if the action calls for OBJ1 then
the order in which the shared ORs were associated will be considered. That means, if
Shared OR1 was first associated then the OBJ1 from Shared OR1 will be taken into
account.
Checkpoints
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.
Below is the checkpoint menu, when the user is NOT in the recording mode.
Standard Checkpoint
It is used to check object property value an compares the actual value with the
expected value during run time. It can be set during recording or editing a test.
Follow the below steps for inserting a standard checkpoint.
1. Start recording, launch flight supplication
2. Enter agent name and password in respective textboxes.
3. Go to Insert > Checkpoint > Standard Checkpoint
4. Point to the ok button on the login screen of flight application, mouse arrow
turns into hand select the ok button
5. Object selection properties dialog box appears
Click on OK button.
Now click the ok button above screen you will see a checkpoint inserted in your code
and also click ok button on flight application screen to complete the login operation.
You can also see the existing checkpoint on the design time
Insert(Design) > Checkpoint > existing checkpoint
Page Checkpoints – A standard checkpoint created for a web page becomes a page
checkpoint. It is used to check no of links and images on a web page. Page checkpoints
can be used to check load time of a page.
1. Open a web page www.google.com
2. Click on the record button first, this time no recording should be there.
3. Insert > Standard Checkpoint >
4. Click on the page
5. Object selection properties dialog box opens
6. Click on the page object
7. Click Ok Button
8. Page checkpoint properties dialog box opens, keep all default properties
selected.
9. The checkpoint is inserted into the script
10. Now stop recording and run the script
11. Click on page checkppint in results viewer.
12. You can see load time no of images
13. No of links (including broken links)
14. All the links
15. Image names and sources can be seen.
Text Area Checkpoint – This is used for windows applications. This compares text
string within a defined area according to criteria specified. It is almost similar to text
checkpoint with only difference is that text checkpoint work on a control whereas text
area checkpoint works on a selected region.
1. Click on the record button first, this time no recording should be there.
2. Launch flight application and enter username and password to login
3. Go to about flight reservation system
4. Click Insert > Checkpoint > select text area checkpoint
5. Drag mouse & select the bottom part where text is written.
6. Object properties dialog selection box opens.
7. Configure text selection properties. Keep them to default here.
8. Stop recording.
9. Run the script.
10. On results viewer go to the checkpoints doublec click to see the details.
11. It will show the selected text in green if passed.
A Text Area checkpoint sample
Bitmap checkpoints are dependent on specific values like RGB values, screen
resolutions, OS so any changes to these values might affect the checkpoint
QTP cannot capture any part of object that is scrolled of screen or hidden by any other
object.
If any app is overlapping your AUT it will be captured in your checkpoint.
Now run the above script and check the results. If the images changes the new as well
as old image will be seen in results viewer.
Text CheckPoint – There will be many instances when we need to check the text
displayed in the application, one way is that we can use standard checkpoint to check
the text property of control.
XML Checkpoint - You can perform checkpoints on XML documents contained in Web
pages or frames, on XML files, and on test objects that support XML.
We need to install web service addins in QTP.
An XML checkpoint is a verification point that compares a current value for a specified
XML element, attribute and/or value with its expected value.
When you insert a checkpoint, QuickTest adds a checkpoint step in the Keyword View
and adds a Check CheckPoint statement in the Expert View.
You can create three types of XML checkpoints:
1. XML Web Page/Frame Checkpoint. Checks an XML document within a Web page or
frame.
2. XML File Checkpoint. Checks a specified XML file.
3. XML Test Object Checkpoint. Checks the XML data for an object or operation.
DataTables – These are used to parameterize the tests and we need to test with
multiple sets of data.
DataTable is just like Microsoft Excel file. The DataTable contains a global sheet and a separate
sheet for each action in the test. So we two types of sheets in data table.
1. Global sheet
2. Local sheet
Global sheet is available to all actions in the test and local sheet is available to the
corresponding action. The best practice is to use local data sheet while parameterizing the test.
Design Time DataTable: While creating editing the test scripts, you enter data directly in the
data table displayed there. You can view data table by selecting View >> Data Table option.
This data table is called Design Time DataTable.
Runtime DataTable: The data table used while running the test is called Runtime DataTable.
The data in the runtime data table may be same as design time data table and/or can be
entered by importing data from excel sheet, text file etc. The runtime data table can be seen in
the Test Results window when run session is ended.
DataTable Parameter:
Each column in global/local sheet of datatable is called a Parameter. We can rename the
parameter just by double clicking on the column header and giving the name to it. Data can be
entered in the column/parameter simply by clicking on the cell and entering the value.
The objects (text box, combo box, links) contained in the frame or Window is
known as child objects.
The below Script gets the all 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