Vous êtes sur la page 1sur 72

1-These QTP tutorials are designed for beginners to advanced users.

Starting from QTP


basics you will learn advance scripting all with practical examples for your easy
understanding.
Considering the big list of these QTP tutorials we!ll be publishing new articles fre"uently.
#eep trac$ of all articles in this Quic$ Test Professional . %ollow the topics closely practice
at home on QTP trial versio
2 -Introduction to QTP Keyword View
This article is going to give you an insight into the Keyword view of the QTP GUI. During this
process we are going to get a quick introduction to ctions! "#$ect %ierarchy and the #asic
colu&ns in the keyword view.
&et!s start.
There is a drop'down #o( at the top and it shows )ction *+.
,hat does this &ean-
'ntroduction to (ctions. Tests in QTP are recorded in ter&s of actions. ction is nothing #ut
a set of state&ents perfor&ing a sequence of actions. /ost often an action is si&ply a
logical unit of &odularity. The calls to one or &ore actions can #e defined as a QTP test.
0or 1.g.. 2et3s assu&e that in an online we# #ased e&ail syste&! the user needs to login!
co&pose and send e&ail and then logout! it is reco&&ended that each of these operations
#e divided into 4 different actions although all of the& can #e written under one action.
5Test 1&ail3 will have.
ction* 62ogin
ction7 68o&pose and send e&ail
ction 4 62ogout
The Test is essentially.
8all to ction*9 8all to ction 79 8all to ction 4
If written in one action! the lines of script would #e large and difficult to &anipulate and
&aintain. :o the logical division is reco&&ended. lso! as we &ove on further in our
e(ploration a#out ctions we are going to understand how actions can #e para&eteri;ed
thus ena#ling easy repetition of a certain action as &any ti&es as desired.
:o when you create a new QTP test it contains a call to one action! )ction *+.
,hen we e(pand the drop down! it shows the Test 0low. 0or a test with &ultiple actions it
shows the sequence in which each action is called thus &aking the na&e! )Test 0low+ self
e(planatory. This drop'down not only displays the sequence of actions! it also provides the
option for the user to select or go'to a particular action to view and<or 1dit.
There is also a )=eusa#le ctions+ 0older view. 0or now! let3s $ust say that reusa#le actions
can #e used #y &ultiple tests and &ultiple ti&es in the sa&e test where it was created. ,e
are going to discuss in detail how that can #e achieved. 1very action #y default is reusa#le.
This can #e changed if need #e.
2et3s take a little diversion here and talk a little #it a#out "#$ect recognition hierarchy in
QTP.
Object Hierarchy > If you have noticed in our e(a&ple the gent ?a&e and Password are
displayed under the ite& 2ogin. point to note here is that! QTP uses a tree hierarchy to
store o#$ects. In our case! the gent ?a&e and Password are the child o#$ects to the
container o#$ect 2ogin which is the Dialog. 8ontainer o#$ects are window! dialog #o( in
a windows #ased environ&ent and we# page in a we# #ased environ&ent.
%ere is an e(a&ple! the login Dialog of the flights application.
The container here is the 2ogin dialog and ne(t level o#$ects are gent na&e! Password and
the other #uttons and i&ages in the dialog. There are only 7 levels here. @ut there could #e
&ore levels! like #rowser.page.#utton in this case! #rowser is a container for page and page
is a container for #utton.
Working with Keyword view:
I a& going to use the test we recorded in the previous article. "pening the flights
application. 1ntering the gent ?a&e and Password in the 2ogin Page and 8licking on "K.
I a& also going to add so&e function calls and state&ents to progra&&atically fro& 1(pert
view and show you how they appear under the ta#ular for& in the Keyword view.
This is the code I put in the expert view:
1
2
3
4
5
6
7
8
9
10
Dialog("Login").WinEdit("Agent Name:").Set "swati"
Dialog("Login").WinEdit("Password:").SetSecure
"511!d"c#$e$%a5&'()$(%c!dd)$%e%ad1!c()c"
Dialog("Login").Win*utton("+,").-lic.
msg$o/ "te/t"
0! /1' 23en
msg$o/ "te/t "
End 0!
Window("4lig3t 5eser6ation").Acti6e7("8as.Ed*o/").29:e "'1'"1"
Window("4lig3t 5eser6ation").Win-om$o*o/("4l9 4rom:").Select "Den6er"
Window("4lig3t 5eser6ation").Win-om$o*o/("4l9 2o:").Select "4ran.!urt"
2ines * through 4 are the login operation. 2ine A is a function call to &essage #o( display
operation. The I added a du&&y if state&ent $ust to show you how it appears in the
keyword view. B is a du&&y value as well. :ince we are not going to run this test! let3s $ust
use it theoretically. 2ines C through *D are entering the date of flight and to! fro& locations.
This is used to understand how o#$ects are grouped.
This code appears as follows in the Keyword view: )clic$ on image to enlarge*
''''''''''''
s you can see there are A colu&ns' Ite&! "peration! Ealue and Docu&entation. The ta#le
can #e e(panded or collapsed #y clicking on the little arrow ne(t to the action na&e.
Item: 1ach step is a sequence of events perfor&ed on an ite&. The ite& can #e one of the
following.
*. Test o#$ect Fe.g.. gent ?a&e 1dit #o(G
7. Utility "#$ect. These are so&e o#$ects reserved #y QTP to #e used in tests. 1.g..
DataTa#le o#$ect. /ore co&ing up on this later.
4. :tate&ent. ny E@ :cript progra&&atic state&ent or even co&&ents
A. 0unction call. like 5&sg#o(3 call in our progra&
Operation: It shows the operation that is perfor&ed on the ite&. ,hen this colu&n is
clicked for a particular ite& it lists all the availa#le operations that can #e perfor&ed on the
o#$ect.
Value: This colu&n can #e considered as the argu&ent of a state&ent displayed. In our
e(a&ple! the &essage #o( function call has a value )Te(t+. There can #e &ultiple argu&ents
to one state&ent in which case this colu&n will #e divided accordingly.
ocumentation: read only colu&n that translates a state&ent into easily
understanda#le co&&ents.
There are two other colu&ns (ssignment and Comment that can #e added to the Keyword
view ta#le. To do so! the option to select isTools-!View Options and choose the required
colu&ns fro& the list displayed.
"ssi#nment: This colu&n is not very widely used and what this does is assigns a value to
or gets a value fro& a varia#le. )clic$ on image to enlarge*
$omments: The tester can write anything under this colu&n. It will #e treated as
co&&ents in the e(pert view.
Conclusion:
,ell! that su&s up an interesting insight into the %asic capa%ilities of the QTP &eyword
view. ctions are logical units of separation in a test. test is therefore a series of function
calls. ,hen a new test is creation it contains one call to an action. @y default all the actions
are reusa#le. QTP follows a &ulti'level hierarchy to recogni;e o#$ects. n o#$ect that
contains a ne(t level of o#$ects is called a container. There can #e &ore than one level of
containers in a test.
In the ne(t article we will talk a#out way we can use this view to Insert :teps. /odify the&!
Insert checkpoints! @reakpoints and how we can &anage actions.
3-Adding Standard Steps From Keyword View
In last tutorial we sawhow to work with keyword view.
Today3s article is going to #e a#out adding steps to a QTP test fro& the keyword view.
@efore we go a#out adding the steps! let3s see what kind of steps we can add at all.
*. 'tandard 'tep: standard step is anything that acts on an o#$ect. 0or e(a&ple! a
set operation on an edit #o( with a particular value or selecting a value fro& a list
#o(.
7. $hec&point 'tep: 8heckpoint is a step in a QTP Test that co&pares an e(pected
value of a specific property<state of an o#$ect with the actual value. This is a kind of
validation that QTP provides to the users to &ake sure their UT is working as
intended. :o! when this kind of a step is inserted! QTP perfor&s a check during this
step e(ecution and if e(pected and actual values are sa&e! the checkpoint passes or
else it fails. n e(a&ple of a checkpoint is! if in an application a check#o( is
supposed to #e "? after its selected or a particular na&e that a te(t on the screen
should #e! etc. QTP has *D checkpoints that it provides the users with. part fro&
these! the tester can verify and validate any conditions #y progra&&atically writing
the&. ll the check points will #e dealt in detail in the co&ing articles.
4. Output value: s the na&e i&plies an output value is nothing #ut a varia#le that
stores the outco&e of a particular step in a test. This value can #e used
su#sequently as an input for another step. This value is only availa#le for the ti&e
period of a test run after which it gets reset. This topic also will #e detailed out
shortly.
A. $omments: ny step that is a non'progra&&atic and won3t #e e(ecuted! #ut is put
in the script to increase reada#ility is a co&&ent.
H. $onditional and (oop statement.
I. Other. These are the kind of state&ents that help in designing the progra&&ing
logic. :o&e e(a&ples are sync state&ent! writing into test results etc.
2et3s start with adding a standard step. 0or our convenience I a& going to e(plain the use of
only ite&! operation! value and docu&entation colu&ns in the keyword view. Though there
are two &ore colu&ns! they are seldo& used.
Inserting a step is the first part of adding a line to a progra&. step &erely adds a #lank
line in your test. It is up to the tester to define the step and to add details to the step. The
details include what ite& to act on! what operation to perfor&! what value to assign etc. If
it3s a new test! any step we are trying to add #eco&es the first step. 0ro& the &enu &ain!
select Insert-! )ew 'tep after clicking anywhere in the keyword view.
)Note - clic$ on any image to enlarge*
nother way is to right click on an e(isting step and selecting Insert new step fro& the
&enu.
@oth of these option result in the addition of a new line after the selected step. If a
container o#$ect was selected while adding a new line! the new step gets added as a su#'
step. If a last'level o#$ect was selected! the new line gets added as a si#ling.
*ere is how the new line loo&s li&e. The new line added is nothing #ut a skeleton that
can #e defined as required.
:o! the first thing you see in a newly inserted line is a 5:elect an ite&3 drop down.
Given the fact that everything operation needs an o#$ect to #e perfor&ed on! this is
inevita#le. ?ow as we already discussed ite& can #e anything! a Test o#$ect! :tate&ent!
Utility "#$ect or co&&ent. The Test o#$ects that are contained under a 8ontainer "#$ect are
displayed here. Therefore! according to our e(a&ple! gent ?a&e! "K! Password is
displayed in the list when a new step is to #e added while clicking on or under the su#'level
steps of the 2ogin Dialog.
O%+ect ,epository:
If anything other than the ite&s listed are required #y the user there is an option to select
the sa&e fro& "#$ect =epository. ?ow! this is the first ti&e in our articles that we have
encountered the word "#$ect =epository. :o! what is it really- ,hen we try to put it si&ply!
an "#$ect =epository is what its na&e suggests. It a place or &ore like a data#ase where all
the "#$ects in a test are stored. This is what happens when the user chooses 5"#$ect
=epository3 fro& the list.
:o either fro& the list displayed or fro& "#$ect repository an ite& can #e selected. The ne(t
thing is to define the operation to #e perfor&ed on the selected o#$ect. 8lick in the
"peration colu&n and a list of operations that can #e perfor&ed on the selected o#$ect are
displayed. This list is dependent on the type of o#$ect selected. 0or instance! a dialog o#$ect
will have different &ethods availa#le than when an 1dit #o( is chosen.
$hoose the desired operation
The ne(t colu&n is the Ealue. s we already know that this colu&n is the argu&ent to the
operation to #e perfor&ed on the selected ite&. "n clicking in this colu&n! the argu&ents
are displayed as shown #elow.
If &ore than one argu&ent is required to carry out the said operation! all the argu&ents will
#e displayed as &ultiple cells in the Ealue colu&n.
The type operation on the 50ly0ro&3 ite& needs a key#oard input. ,hen the icon in this
colu&n is displayed the following dialog is displayed that helps the user to configure this
value.
s you can see fro& the window a#ove! the value to #e entered in this field can either #e a
58onstant3 in which case the constant value can si&ply #e typed in the te(t #o( and then
followed #y clicking the 5"K3 #utton in the window.
"r it could #e para&eteri;ed! which &eans it would #e picked up fro& a location in the data
sheet! a rando& nu&#er or an 1nviron&ent varia#le. %ow to para&eteri;e a value for an
argu&ent will #e discussed in length later on.
In our e(a&ple! I a& writing )Test+ in the constant field and clicking "K and here is how the
line generated looks.
It should #e noted that the 5Docu&entation3 field gets auto'populated with the description
pertaining to the operation perfor&ed on the ite& selected.
Conclusion
:o! that concludes the topic! 5dding a standard step to a test fro& the Keyword Eiew3. ,e
have discussed the various kinds of steps that can #e added fro& the Keyword view and
e(plored the adding of a :tandard :tep in detail.
,e3ll have couple of &ore articles on QTP keyword view. In the co&ing articles! we will see
how to add the other kinds of steps! adding conditional and loop state&ents and how the
Keyword view can #e used to &odify<delete the test steps.
--"ddin# $onditional and (oop 'tatements in Keyword View.
Understanding QTP keyword and e(pert view feature in detail is very i&portant to learn QTP.
:o we have divided this Keyword Eiew tutorials in four articles. This is the third article in
Keyword Eiew series.
8heck out all the articles in this QTP training series J Quick Test Professional FQTPG training
series
)+ote - Clic$ on any image to enlarge*
Condition and Loop Statements in Keyword view
( "uic$ recap of what we learned so far '
,e acquainted ourselves with the Keyword Eiew of the QTP and we are trying to understand
the different features this view provides and see how these features can #e used to write
effective tests. To do that! we are working with a #asic e(a&ple where we recorded a series
of si&ple operations on the :a&ple 0light pplication.
This aids in understanding how QTP translates the steps perfor&ed on the application into a
ta#le with A essential colu&ns of the Keyword view. ?ot only does QTP show the user the
operations perfor&ed in ter&s of a ta#le #ut also lets the user &anipulate the steps fro&
this very ta#le.
,e have e(plored how a standard step can #e added to the keyword view. part fro& a
standard step! this view also displays the conditional and loop state&ents in a test.
In this article we are going to e(plore how QTP3s Keyword view handles these state&ents.
Firstly, what do Loop and If statements do?
Loop 'tatement: This is a part of progra&&ing logic that is used when a particular set of
state&ents have to #e e(ecuted repeatedly for a particular nu&#er or ti&es. nother
variation to this state&ent is to repeat e(ecution for a #lock of code until a certain condition
is satisfied or while the said condition is satisfied.
If statement: s the na&e indicates! the if state&ent in a progra& is used to perfor& a
check for a certain condition to #e satisfied! and when it does a certain #lock of code gets
e(ecuted. Eariations to an 5if3 state&ent is 5if ..else3 and 5if else ifK3
Keyword view has a different icon to indicate each of these state&ents in the keyword view.
2et3s include so&e du&&y steps into our progra& and see how these state&ents appear in
the keyword view. 0or convenience and since the steps that I a& a#out to insert are
du&&y! I a& going to put the code directly into 1(pert view and we o#serve it in keyword
view.
/0 $onditional statements:
The a#ove is the different variations of the 5if3 state&ent that I entered in the e(pert view
and as I said all the code does not serve any purpose e(cept for our understanding. ,e will
note how these state&ents are represented in the keyword view.
s you can see each state&ent type is given a different icon for identification.
20 (oop 'tatements:
2et3s look at how these state&ents are represented. ,e will follow the e(act &ethod that we
did for conditional state&ent.
Adding condition statements to the keyword view:
0or &y e(a&ples a#ove I have added the conditional state&ents fro& the 1(pert view and
we &erely looked at their representation in the Keyword view. :o far we have not added
the& directly fro& the keyword view. Keyword view does provide a way for these
state&ents to #e added directly to the test. %ere is how you can do it.
8lick anywhere in the keyword view! $ust like how you would do it to add a standard
state&ent! right click and choose )Insert'6:tep+ followed #y )8onditional :tate&ent+ and
the state&ent that you would need. %ere is how it looks.
s you can see a#ove! n If..Then! 1lseif..then! 1lse are the state&ents that can #e chosen
#ased on the require&ent of the tester.
2et us choose an 5if..then3 and see what happens.
This is what gets inserted. ?ow! $ust the way we would do for a standard step! we will need
to define a conditional state&ent too.
Item. 8lick on the 5ite&3 colu&n corresponding to the 5if3 state&ent and all the o#$ects
availa#le will #e displayed. This feature again is no different fro& the standard step
definition. :o choose an o#$ect that you wish to act on. s an e(a&ple! I a& going to check
if the 5Password3 field e(ists. :o I choose )Password+ fro& the list.
Operation. gain! a list of all the functions availa#le will #e displayed when this colu&n is
clicked on. :ince I a& checking if the password field e(ists or not! I will choose 51(ist3
Value. The argu&ent<argu&ents for the function is what this field is. 0or the 51(ist3 function
an argu&ent is not necessary so we will leave it e&pty.
2et us now look at how this new state&ent looks in the keyword view as well as what it
looks like in 1(pert view.
Keyword view
1xpert view:
''''''''''''
s you can see! the 5if3 state&ent is defined.
?ow! we have to add code or state&ents to define what needs to #e done if the condition
#eco&es true.
0or the sake of our e(a&ple! if the password #o( e(ists we will enter a value in the field.
%ow can we acco&plish this- Once a conditional or loop statement are added any
steps that the user adds or records will %e directly added under them unless
explicitly specified. The statement added or recorded could %e a standard step or
another conditional or loop statements 2nestin#0.
:o! to define the 5Then3 part of our 5if3 state&ent! I a& going to record the action of entering
the password value. To do so! I will choose 5=ecord3 fro& the &enu options and enter a
password value in the 50lights3 2ogin page. Take a look at the screen shots #elow! the
recorded state&ent got directly added under the 5if3 state&ent.
ny steps you add further will #e added under to the 5if..then3 #lock.
To want to add outside the #lock! select the #lock Fthe 5if3 state&entG! right click and choose
5Insert ?ew :tep after #lock3
The new step $ust co&es as a si#ling to the 5if3 #lock.
?ow! that we have understood the #asic functionality it goes without saying that all the
other conditional state&ents work the sa&e way and any of the& can #e used as needed #y
the progra&&er3s logic.
Adding Loop statements to the keyword view:
The procedure to add the loop state&ent is #y right clicking in the keyword where you want
it inserted and choosing )Insert ?ew :tep'62oop :tate&ent+ and the required option.
s always! the inserted step has to #e defined. ny steps recorded or added after the loop
will #e within the #lock and to e(it the #lock the user has to #e e(plicitly specify that the
new step is to #e added outside the #lock #y right clicking on the loop state&ent and
choosing )Insert ?ew step after #lock+ option.
&et us add a ,%or! Statement as an example.
I chose the )0or+ fro& the &enu option and this is what gets inserted into the keyword
view.
In the value colu&n I will set the iterator value. I set it as * to 4. ?e(t I added a state&ent
as )&sg#o( )(++. 2et3s look at how this looks in the keyword view.
Conclusion:
:o! that concludes our session on the conditional and loop state&ents and how they can #e
inserted fro& the keyword view. If or loop state&ents can #e pretty &uch added $ust the
way a standard step is added. Lust like a standard step these steps also need to #e defined.
:teps that are recorded or added after a #lock state&ent will #e added within the #lock #y
default unless specified. ,hen a state&ent has to #e added outside the loop we need to
choose the option )Insert new step after #lock+ option fro& the right click &enu after
choosing the #lock after which we desire the steps to follow.
'n the next session we will explore more options of the $eyword view such as moving and
deleting steps adding and deleting brea$points.
3 - movin# steps4 deletin# steps and dealin# with %rea&points in &eyword view.
This is the fourth and the last article on QTP &eyword view features.
If you &issed any article in this QTPtraining series please check all articles on this
page. QTP Trainin# Tutorials
Other features of the Keyword View:
,e are al&ost approaching the end of sessions concerning the 5Keyword Eiew3 of QTP. %ow
it looks! what it does! what can we do with it > These are so&e of the aspects we are trying
to unveil in the course of our articles. Understanding the view! adding steps! conditional
state&ents are already dealt with.
Today well learn remaining eyword !iew feat"res s"ch as mo#ing steps,
deleting steps and dealing with brea$points%
Lust like always! we will use the sa&ple test we have #een working with > The login
operation on the 0light sa&ple application.
Moving steps:
/0 The first and the si&plest way > Keyword view acts like any te(t &odification application
when it co&es to cutting! copying and pasting the steps. Thus! all the clip#oard shortcuts
are applica#le.
8trlM8 > 8opying
8trlME > /oving
8trlMB' 8ut
20 The ne(t way is #y choosing the &enu option. To use this! select the step that needs to
#e &oved and choose the following &enu choices.
1dit'68ut
1dit'68opy
1dit'6Paste
50 The other &ethod is dragging and dropping.
ny of the a#ove &ethods can #e used to &ove steps. %owever! there are few ground
rules:
*. The loop or condition state&ents can only #e &oved in #locks. 0or e(a&ple! for an
5ifKelse3 state&ent you cannot $ust &ove the else part.
7. In a step! where the ite& is a child o#$ect and the user decides to &ove it! there is
one of the two scenarios that co&e up. 1ither the step gets &oved under the sa&e
parent or to a different parent. If it is &oved under the sa&e parent! it si&ply co&es
up in the new position chosen. @ut if it is &oved under a different parent! the parent
gets duplicated. 2et3s see this pictorially.
)Note - clic$ on any image to enlarge*
I a& going to &ove the step where we enter the agent na&e Fthe one highlighted a#oveG
under the 50light =eservation3 parent o#$ect. 2et3s note that the parent o#$ect for 5gent
?a&e3 is 2ogin. I si&ply dragged the step to #e the last one. This is how! it appears.
1arlier in the introduction sessions! we have discussed that we can have &ultiple actions in
a test. 2et us see how a test with &ultiple actions would appear in the keyword view and
how this view can #e used these actions as desired.
To achieve this is! I a& si&ply going to convert all the steps under the parent o#$ect 50light
=eservation3 in our a#ove e(a&ple to appear under another action. dding actions! steps to
actions all these are going to #e discussed in detail as we &ove on in our sessions.
"ction /:
"ction2:
s you can notice in the test flow pane! the sequence in which these actions are e(ecuted is
displayed.
If I would want the ction 7 to run first followed #y ction *! keyword view let3s &e do that
#y allowing &e to drag and drop the actions to the necessary position.
,ith this! we have covered all the infor&ation necessary to &ove steps<actions<#locks
within a test using the keyword view.
Delete Steps:
Deleting steps fro& QTP could not have #een si&pler. ll you need to do is choose the step
that you do not want in the test and si&ply hit the )Delete+ #utton on the key#oard or right
click on a step and select )Delete+ fro& the &enu or select a step and choose )1dit'
6Delete+ fro& the &ain &enu.
If a step that has su#'steps defined for it is chosen for deletion! the following &essage is
displayed to the user.
''''''''''''
,hat this &eans is that! if a step with su#'steps is chosen for deletion! all the su#'steps get
deleted too.
nd! that3s all there is to discuss a#out deleting steps.
Adding Breakpoints to the test from the keyword view:
"ften! during the e(ecution there &ight #e one or &ore things that you want to key an eye
out for and o#serve what kind of changes are happening. This &ight #e to see the state an
"#$ect gets to or to note a value a varia#le takes etc. facility that helps us do $ust that is a
@reakpoint. It is #asically a certain point in your test where you want to pause the test run
and o#serve or o#tain certain infor&ation a#out your test. /ost ti&es this feature &akes
de#ugging easier.
?ow! that we know what a #reakpoint is! we will try to understand how to add the& to our
tests fro& the keyword view.
ll you need to do is! click in the left &argin at the particular step where you need to pause
the test. The addition of a #reakpoint is represented #y a red dot in the left &argin
corresponding to the step where a #reak is added.
%ere is how it looks.
:electing a step and pressing 0N on the key#oard also results in the addition of a
#reakpoint.
2astly! the &enu option )De#ug'6Insert<=e&ove @reakpoint+ can also #e used.
:o! once a #reakpoint gets inserted! the test will run until the step where it is inserted
nor&ally and will co&e to a halt #efore e(ecuting it. t the point the tester can perfor& the
required o#servations for which the progra& was stopped and continue to run it #y choosing
the )=un+ option one &ore ti&e fro& the &ain &enu whenever he is ready.
If we add a #reakpoint fro& the keyword view! the sa&e is displayed in the 1(pert view also
in front of the line corresponding to the row to which it gets added.
The vice versa is true too! if you add a #reakpoint fro& the 1(pert view! it gets reflected in
the keyword view.
s si&ple as it is to insert a #reakpoint it is even si&pler to delete is once its purpose is
served or when it is no longer needed.
elete 6rea&points
8licking one &ore ti&e on the line where the #reakpoint already e(ists will result in its
deletion. Keyword 0N or the &enu option )De#ug'6Insert or Delete @reakpoint+ can #e
chosen on a step with a #reakpoint and it gets re&oved.
Conclusion:
:o this concludes the discussion of all the properties and capa#ilities of keyword view in
detail. This view is the &ost reada#le one a&ong the two and once all the features are
understood! we can use it as effectively as possi#le to &ake the tests ro#ust.
Ne&t we will deal with how to record a new test and what are the factors that
determine the s"ccess of a being able to do so%
The last few QTP tutorials have #een a#out the QTP3s Keyword view which was really crucial
in getting a high'level understanding of a QTP test3s structure and also introduced us to few
ways in which our tests can #e tailored to &eet our needs. :o I think we are ready to
record our first test in its entirety. ,e are going to do $ust that in the ne(t few QTP training
articles. Today3s topic! therefore is the first step in doing so which is the )=ecord and =un
settings3. ,e are going to understand all a#out this! why it is i&portant and how this can
affect a test.
6-Record and Run Settings Dialog
,hen QTP is launched and we choose to record a new test! the 5record and run settings3
dialog opens up. lternately a user can choose to access this window #y choosing
)(utomation--.ecord and .un Settings+ option fro& the &enu. :o far in our e(a&ples we
have $ust continued with its default settings #ut now we will e(plore it further. The following
is the how this dialog looks.
s the sa&e suggests! this is a space that QTP provides the user to set certain para&eters
that help the user to create a test via record and to e(ecute the sa&e during a run session.
QTP can record and run a test on either a windows app or a web app. The we# ta# is
availa#le only when the ,e# add'in is selected to #e loaded at start up. This ta# is used for
,e#! .?1T ,e# 0or&s! People:oft! and ,e#'#ased :P o#$ects. :o there are 7 ta#s to
define the settings separately for each of these environ&ents. There will #e a separate
5:ie#el3 ta# availa#le is a :ie#el add'in is installed and loaded during start up.
&et!s loo$ at the ,/eb! tab first01
Web Tab on Record and Run Settings Dialog:
The default settings are as shown in the picture a#ove. This setting &eans that when a
record session is started the target of the record operation can #e any of the we#
application that is already open in a #rowser. The user also has a instruct QTP to ignore
certain we# pages like Q8 or any other page with a specific U=2 or a specific title. The way
he can do that is! )Tools--2ptions--/eb+ and define those pages in the following QTP
dialog.
@ut if the user chooses! the ne(t option )"pen the following address when a record or run
session #egins+ the corresponding ele&ents in the screen get ena#led. Take a look at it
#elow.
The user can enter the address of any page and the choice of the #rowser. The #rowsers
that QTP ** supports are.
The #rowsers that are supported and are currently installed in your &achine will only appear
in the list.
There is another way to set the record and run settings other than fro& this window and
that &ethod is through 1nviron&ent varia#les. :ince we did not yet get there! we will
discuss the& in detail later on. 0or the sake of &entioning! if the environ&ent
varia#les 7,(8env and6rowser8env are set! then it overrides the U=2 and #rowser
chosen in the 5=ecord and =un :etting3 window. %ow to create these and how they work >
all this will #e dealt with later.
5Do not record and run on #rowsers that are already open 5> If this option is chosen all the
#rowsers that are open prior to recording and running and also prior to launching QTP will
#e ignored. It is as if these #rowsers don3t e(ist for QTP #ecause the user can not even spy
these pages to view the o#$ects. In other words! these #rowsers are totally ignored and as a
result dee&ed inaccessi#le to QTP.
58lose the #rowser when the test closes3 > this option when chosen will close the #rowsers
on which the record and<or run session was carried out when the test ends.
Windows Tab on Record and Run Settings Dialog:
This ta# is for the windows #ased applications. The default option to record and run on any
windows app opened.
''''''''''''
If the 9,ecord and ,un only on: option is chosen4 the other options under it #et
activated.
1. (pplications opened by Quic$Test' when this option is chosen! the applications that
are opened as a result of an invoke operation perfor&ed #y Quick Test are only
chosen for recording
2. (pplications opened via the 3es$top 4by the /indows shell51This &eans that the
application that are opened fro& a windows desktop are chosen
3. (pplications specified below1 choosing this option will open another child window
where a specific app to #e opened #y the QTP at the #eginning of a record or run
session can #e defined.
s you can see fro& the a#ove window! the path of an application and its folder should #e
added and QTP opens that particular app while record and<or run.
That concludes a quick introduction to various ;record and run settin#s: that can #e used
for a QTP test. ,hen testing a we# app! it is also i&portant to &ake sure that we add the
correct settings in the windows application ta# too. It is crucial #ecause! it will help us in
preventing opening up of unnecessary applications and also to &ake sure that we do not
accidentally change any of the already open windows applications. It should #e noted that!
the setting in the windows ta# do not directly affect the testing perfor&ed on a we# app.
'o the recommended settin#s for the windows ta% while testin# a we% app are:
"nce these settings are done! the test recording #egins. ny operation perfor&ed on the
test gets recorded in the QTP. The tester can stop the record operation once all the steps
that he wished to perfor& on the UT are done #y clicking on the ):T"P+ option availa#le in
the QTP &enu.
The recorded steps can then #e re'perfor&ed on the UT #y choosing 5=U?3 option fro&
QTP. =un operation too invokes the application Fwe# or windowsG depending on the setting
specified.
Conclusion
This for&s the #asis for perfor&ing any #asic steps on the UT using QTP. In the real world
this alone isn3t sufficient. Testing as an activity is verification and validation inclusive! so we
will have to tailor these #asic lines of code to include certain verification and validation
points. To do so! QTP provides so&e checkpoints and the tester can also progra&&atically
add steps to check few things as needed.
,e will discuss these checkpoints in the co&ing series of articles and also try to learn the
#est practices to #e followed while test creation to ensure &a(i&u& efficiency.
()How *T+ Identify Object ,ni-"ely? . This is the (th *T+ T"torial in o"r *T+
training series%
,e are getting ourselves equipped with all the #asic concepts that will ena#le us to
writerob"st *T+ tests. ,e have covered the QTPrecord and run settings! working with
keyword view and the other related topics.
This is the ne(t article in the series that talks a#out a crucial aspect of QTP > The
mechanism it uses to identify an o%+ect uni<uely. ,hen you look at the #elow screen.
There are 4 #uttons and 7 te(t #o(es along with various other ele&ents in this dialog.
In the previous e(a&ples! when we entered the user na&e and password we saw how QTP
recorded the sa&e operations in ter&s of progra&&atic code as well as a ta#le in keyword
view. ?ow! during play #ack how does QTP know that the value we provide as gent ?a&e
or Password has to go respectively in those edit #o(es. "r how does it know which #utton to
click to su#&it the values entered-
2et us try to find an answer to that.
It is clear that QTP so&ehow re&e&#ers which o#$ect to act on. The way it does it is! it
stores the o#$ect in the UT as a test o#$ect. It then e(a&ines its properties and classifies
the o#$ect. 0or 1.g.. when it encounters the "K #utton it e(a&ines its properties and #ased
on these! it classifies the o#$ect as a 5,in@utton3.
QTP has a predeter&ined set of properties that it learns<stores for every class of o#$ect it
identifies. There are 4 aspects to this.
*. =andatory properties. This is the list of properties for a certain class that QTP
always stores. ,e could say that this is the o#$ect description. It also checks this in
con$unction with the parent o#$ect to see if the description is sufficient to identify the
o#$ect uniquely.
7. "ssistive properties. In case the description of &andatory properties is insufficient
to identify the "#$ect a set of non'&andatory properties will #e added to the
description one after the other until there is enough data to identify the o#$ect.
4. Ordinal Identifier. If the assistive properties also do not result in unique
identification of an o#$ect a special ordinal identifier is added #y QTP! such as the
o#$ect3s location on the page or in the source code.
:o! this is how QTP for&s Test "#$ects. It uses this Test "#$ect description to search for the
o#$ects to act on during a run session. It chooses the o#$ects that &atch perfectly with the
description it contains. These o#$ects are called ,un-Time o%+ects.
Unless your application has changed significantly the Test "#$ect description that QTP has is
sufficient to find an o#$ect.
0or the ,in@utton o#$ect that we have in our 0light app! let us see what properties QTP has
stored. This infor&ation is availa#le in the "#$ect =epository. /enu option )=esources'
6"#$ect =epository+ will launch the "= for us. lternately! you can use 8T=2M= or click on
the icon.
If you notice in the a#ove window! it stored the 5te(t3 in the ,in@utton as its description to
identify this #utton at runti&e.
0or &ore co&plicated applications! the tester can add or re&ove certain properties to &ake
the description ro#ust enough to identify the o#$ect at runti&e &ore precisely. To do this!
si&ply click on the 5M3 icon.
ll the other properties of the o#$ect will #e displayed. The user can choose to add one or
&ore of these properties.
There is also so&ething called )Visual ,elation Identifier+ in the "= screen for the
,in@utton properties.
This is a feature that further supports the o#$ect recognition according to their neigh#oring
o#$ects in the UT. "nce set! this creates a kind of link for the less sta#le co&ponents in
your UT with the o#$ects that are &ore uniquely identifia#le. QTP will identify these o#$ects
as long as they &aintain their relative position to these unique o#$ects.
To set a kind of positional link we are going to have to click on this colu&n in the "= and
the following screen co&es up.
In this screen select the 5M3 sign to add an o#$ect with which you want your test o#$ect to
have a positional link.
I will choose )gent ?a&e+ and say that this o#$ect should #e a#ove )"K+#utton.
This is how I set that.
?ow! in case so&e properties of "K #utton changes in the future! QTP will identify it if!
)gent ?a&e+ is a#ove it.
'mart identification:
This is the &echanis& e&ployed #y QTP under one of these two situations. The description
for an o#$ect that QTP has.
*. does not &atch with any run ti&e o#$ects
7. /atches with &ultiple o#$ects
This is a little #it of an advanced concept! so we will get to it at a later ti&e via so&e
e(a&ple for easy and ela#orate understanding.
''''''''''''
Ordinal identifier:
This is a nu&eric value that depicts the relative order of the o#$ect with o#$ects that have a
si&ilar description. If an o#$ect * and "#$ect 7 have the sa&e &andatory and assistive
properties! then the ordinal identifier will #e used to recogni;e the o#$ect uniquely. This
value is related to the other o#$ects of the screen! so in case anything changes in the
screen! this identifier &ight not co&e useful.
It should #e noted that! if the &andatory and assistive properties are enough then an
ordinal identifier is not assigned during record. It can #e added later on #y clicking on the
respective colu&n for the o#$ect in the "=
There are 5 &inds of ordinal identifiers:
*. Inde(. this is #ased on the order of appearance of an o#$ect in the application code
7. 2ocation. #ased on the location in a screen or dialog or page
4. 8reation Ti&e. This is used only for #rowser o#$ects. In case 7 #rowsers with si&ilar
properties e(ist! then the one that is created first and ne(t are considered.
0or e(a&ple! 2et us understand how 5inde(3 identifier works in our 0light applications login
screen.
These are the following co&ponents.
s you can see! the static te(t and the edit #o(es have the sa&e 5te(t3 property.
If I know that one of the& is a static te(t and the other is ,in1dit o#$ect! then there is no
pro#le& at all. :ay if all these are treated as ,in"#$ect then I will have to specify which
o#$ect to act on. This is only going to happen when the &andatory! assistive and s&art
identification have failed. :o in order to tell QTP which is what! I a& going to assign an
5Inde(3 ordinal identifier. I will do so fro& the "=.
I will set the gent na&e static te(t identifier as D and for the edit#o( I will set it as *.
This is how it loo$s1
:o if I need to access the static te(t then I will do so as follows.
/in2b6ect47text18(gent +ame10 index1895 : This will refer to the static text
/in2b6ect47text18(gent +ame10 index1815 : This will refer to ;dit box
The sa&e theory applies to 2ocation identifier too e(cept that we will choose the location in
the window to deter&ine the nu&eric value that is applica#le to a certain o#$ect.
$onfi#urin# O%+ect identification properties:
The &andatory! assistive properties and ordinal identifiers to #e considered for an o#$ect of
a certain class to #e recogni;ed can #e configured #y using )Tools'6"#$ect Identifier+. ,e
can also set the s&art identification properties through this window.
The window looks as follows.
s can #e seen in this a#ove i&age! the environ&ent can #e chosen fro& the drop'down
#o(. "nce that is chosen the classes of o#$ects in the corresponding environ&ents are
shown in the list. fter an o#$ect is selected! the &andatory and assistive properties are
displayed. The user can dd<=e&ove additional properties to this list.
lso s&art identification can #e ena#led<disa#led for a certain class of o#$ect when needed.
To set the ordinal identifier there is a drop'down that can #e chosen to identify the o#$ect
using 2ocation! Inde( or 8reation Ti&e Fonly for #rowser type onlyG.
/e will wrap up the fundamental concepts before moving on to full-fledged QTP programs.
The next QTP article will have the different recording modes 2b6ect Spy 2b6ect .epository
etc. details.
> -,ecordin# =odes in QTP:
=ecording is the &ost co&&only used &ethod to create a test. The #asic steps are typically
recorded and the test later under goes i&prove&ents in order to suit the needs of
the testing process.
QTP provides 4 &odes of recording.
*. ?or&al
7. 2ow'level
4. nalog
Though only the nor&al recording &ode gets used &ost of the ti&es! it is i&portant to
know the others too! as the knowledge a#out the sa&e can co&e handy when the need
arises for the&.
)ormal ,ecordin# mode' The default recording &ethod is always the nor&al &ode. In all
our previous articles when we say record we &eant the nor&al &ode. :o! as we know this
&ethod uses the &odel of Test "#$ects and =unti&e o#$ects to learn and act on the UT.
"nalo# recordin# mode' records the e(act &ouse and key strokesthat the user perfor&s
in relation to either the screen or UT window. The steps that are recorded using this
&ethod cannot #e edited.
The way this usually gets represented in a code is.
/indow<app..un(nalog 7Trac$10
"ne scenario in which this type of recording can #e used is when we are trying to capture a
signature.
(ow (evel recordin# mode- This &ode records the co'ordinates in the application where
the operation is perfor&ed! irrespective of whether QTP recogni;es the specific "#$ect or
"peration.
Some important points to note about these different modes are1
*. In the &iddle of recording! we can switch to nalog<2ow'level &ode! finish the task
required and go #ack to nor&al recording
7. nalog and 2ow'level recording &odes require &ore &e&ory space than the nor&al
&ode.
4. /ouse &ove&ents are not recorded in the low'level recording &ode
A. The switch to nalog &ode is availa#le only during recording and not during editing
H. The test that is recorded in an analog &ode will fail if it is run after changing
the screen resolution.
The &enu option to change the recording &ode is.
O%+ect 'py:
"#$ect :py is an e(tre&ely helpful tool that QTP has to view the properties and operations
of an o#$ect in the UT. The prerequisite to using this tool is that the UT has to #e opened.
The "#$ect :py can #e accessed #y using )Tools'6"#$ect :py+ or #y directly clicking on the
#elow
It is also availa#le fro& the "#$ect repository and "#$ect repository &anager windows.
,hen "#$ect :py is launched! this is how its interface looks.
@y clicking on the pointy hand you can point to any o#$ect whose properties you wish to
e(a&ine.
This is how it displays the properties.
s you can see! it shows all the properties of the o#$ect and the corresponding values. It
shows the o#$ect hierarchy. There is also an 5"perations3 ta# which when clicked displays all
the operations that can #e perfor&ed on the test o#$ect.
The spy not only displays the properties! it also has a provision that lets the users add a
certain o#$ect to the "=.
Oou can do that #y clicking on the "= icon with a M in it.
O%+ect ,epository
In one of the previous articles we talked a#out how an "= is like a warehouse where all your
o#$ects are stored.
''''''''''''
"= has the list of "#$ects that QTP learned during the record process and the class to which
they #elong. It stores the set of properties that uniquely identifies the "#$ect FdescriptionG
and also na&es the o#$ect for the sake of identification in our test! #ased on its &ost
pro&inent feature.
The o#$ects that are acted upon during record get auto&atically added to the "=.
lternately! the user can add additional o#$ects on a need #asis. This can #e done directly
fro& the "= window or fro& "#$ect :py. F8trlM= or =esources'6"#$ect =epository or click
on the icon.G
There are two &inds of repositories:
*. 2ocal
7. :hared
1very ti&e a test is created we have seen that a call to ction * is the only state&ent #y
default. ,e can add other actions and call the& as needed. :o! for every action QTP creates
its own local repository #y default. It contains the o#$ects that are related to that particular
action.
8onversely! the user &ay decide to use a co&&on repository for &ultiple actions in which
case! this repository is to #e associated with the actions and all of the& can share the
o#$ects that it contains. This can #e done using the )"#$ect =epository &anager3. The
o#$ects can #e e(ported fro& a local repository into the shared one to &aintain a single
location for all the o#$ects. lso! a shared repository is read'only in the action level and any
changes to it have to #e &ade via 5"#$ect =epository &anager3.
The repository to #e used #y an action has to #e specified in the action properties.
%ow is it done practically is so&ething we will look into using so&e e(a&ples later on.
Some of the important points to note here are1
*. 1ven though there is a single shared repository for all actions every action will have
its own local repository whether the test uses it or not. ?or example: 0or test * if
there are ction D! ction * and ction 7 and there is a shared repository "=:hared!
there will #e local repositories "=D! "=* and "=7 #y default. %owever! if all the
actions use one shared repository! local "= will #e e&pty.
7. If a local "= and :hared "= have an o#$ect with the sa&e na&e! the action will
consider the o#$ect in its local "=.
4. There can #e &ore than one :hared "=3s associated to the sa&e action. If :hared
"=* and :hared "=7 have one o#$ect na&ed "@L* each and if the action calls for
"@L* then the order in which the shared "=s were associated will #e considered.
That &eans! if :hared "=* was first associated then the "@L* fro& :hared "=* will
#e taken into account.
It goes without saying that having a shared "#$ect =epository is &ore efficient as it helps in
easy &aintenance and you can use one o#$ect description across &ultiple actions.
%ere we covered so&e of the key concepts that will ena#le us to understand and create
#etter QTP Tests. In &y opinion infor&ation on ctions! ctive screen and a rather
i&pro&ptu #ut i&portant password encoder tool are few &ore aspects we will have to cover
#efore we &ove to &ore advanced topics.
9-Basic of VB Scripting Concepts to Learn QTP
It should #e noted that this article is not an e(haustive list of all the E@ :cript features.
8onsider this as a place that will introduce you to certain key concepts to guide you while
you atte&pt to self'learn the language. :ince the e(pert view of QTP is a E@ :cript editor! it
is a &ust that we try to understand E@script for QTP #efore we &ove on to our articles on
QTP 1(pert Eiew.
E@:cript data types and su#types.
Data types:
*G There is only one data type. Variant. It can store different kinds of infor&ation #ased on
the conte(t in which it is used.
7G If used in a nu&eric conte(t it is a nu&#er or a string if used in a string e(pression.
4G If a nu&#er has to #ehave as a string we could enclose it within ) ).
AG There are various su#types to a variant. Oou can e(plicitly specify these su#types to
achieve a clear definition for your data. The #elow is a screen shot fro& the E@ User guide
that shows all the su#types of data that can #e used.
4clic$ on image to enlarge5
HG 8onversion functions can #e used to convert one su#type of data into another.
IG :ince it is the only data type availa#le! all the return values fro& a function are variants.
%ere are different E@:cripting e(a&ples you can try on your own.
Variables:
/0 varia#le is nothing #ut a space in the co&puter3s &e&ory that can store certain
infor&ation. This infor&ation is #ound to change fro& ti&e to ti&e. ,here the infor&ation
goes physically is i&&aterial #ut when needed! it can #e accessed or changed #y addressing
the na&e of the varia#le.
1.g. If there is state&ent that you want to run a nu&#er of ti&es! you could use a varia#le
to contain that count. :ay B. B is a varia#le that can #e used to stored! change and use the
space in the &e&ory where we want to keep the count.
20 ll varia#les are of the datatype Eariant.
50 Declaring a varia#le prior to its use is optional! although it3s a good practice to do so.
-0 To &ake the declaration &andatory there is a )Option 1xplicit@:tate&ent availa#le.To
declare varia#les.
Di& ( > This declares (
Di& (! y! ; > This declares &ultiple varia#les
BP*D > This is how a value is assigned. s a general rule! the varia#le is the left hand
side co&ponent and the right is its value.
BP+:wati+ > this is the way a string value is assigned.
To &ake declarations &andatory this is how the code has to #e written.
2ption ;xplicit
3im x stri
If "ption e(plicit state&ent was not used! we could have directly written.
x8199
stri80Swati0
and it would not have thrown an error.
30 )amin# convention. ?a&es &ust start with an alpha#etic character! &ust #e unique!
cannot contain and e&#edded period and cannot e(ceed 7HH chars.
A0 varia#le containing a single value is a scalar varia#le and the one that has &ore than
one is an array.
B0 one di&ensional rray can #e declared as. Di& F*DG. ll the arrays in E@ :cript are
;ero #ased that &eans the array inde( starts fro& D through the nu&#er declared. That
&eans! our array has ** ele&ents. :tarting fro& D to *D.
>0 To declare a 7 di&ensional array si&ply separate the row count and colu&n count #y a
co&&a. 1g. Di& FH! 4G. This &eans it has I rows and A colu&ns. The first nu&#er is
always row and the second always a co&&a.
C0 There is also a dyna&ic array whose si;e can change during run ti&e. These arrays can
#e declared using di& or redi& state&ents.
''''''''''''
If an array is declared as Di& F*DG and during run ti&e if we need &ore space we can so
the sa&e #y using the state&ent. redi& F*DG. There is a )Preserve+ state&ent that can #e
used in con$unction with the redi& state&ent.
Di& F*D!*DG
KK
K.
=edi& preserve F*D!7DG
This piece of code shows how we do it. Initially is a ** #y ** array. Then we are resi;ing it
to #e a ** #y 7* array and the preserve state&ent will &ake sure that the data that is
previously contained in the array is not lost.
Constants:
*. s the na&e i&plies a constant is nothing #ut an unchanging value in a progra& that
is assigned a na&e.
7. They can #e declared #y prefi(ing )8onst+ to a na&e.
4. 1g. 8onst aP+*D+ or 8onst strP+:wati+.
A. This value cannot #e changed accidentally while the script is running.
Operators:
:o&e of the i&portant operators that are &ost co&&only used are.
*. :tring concatenation. Q F1g. Di& (P+good+Q+day+! so ( contains )goodday+
7. ddition FMG
4. :u#traction F'G
A. /ultiplication FRG
H. DivisionF<G
I. 2ogical negation F?otG
S. 2ogical con$unction FndG
C. 2ogical dis$unction F "rG
N. 1qualityFPG
*D. Inequality FT6G
**. 2ess than FTG
*7. Greater thanF6G
*4. 2ess than or equal toFTPG
*A. Greater than or equal to F6PG
*H. "#$ect equivalenceFIsG
It is i&portant to note that the list is not co&plete #ut &erely a su#set containing the &ost
co&&only used operators.
The operator precedence rules are.
*. /ultiplication or Division take precedence over addition or su#traction
7. If &ultiplication and division e(ist in the sa&e e(pression! then left to right order is
considered
4. If ddition and su#traction occur in the sa&e e(pression!then too! left and right
order is taken into consideration.
A. The order can #e over ridden #y using parenthesis. In this case! the e(pression
within the parenthesis is e(ecuted first.
H. Q operator takes precedence after all arith&etic operators and #efore all logical
operators.
Conclusion
:o! this #eing the E@:cript #asics! in the co&ing article we will look into how we can write
loop and conditional state&ents that are essential in #uilding the progra&&ing logic. The
ne(t article will #e the last in the E@ :cript series #efore we &ove on #ack to QTP3s e(pert
view.
/D-V6 :cripting @asics E Fritin# (oop and $onditional 'tatements for 6uildin# the
Pro#rammin# (o#ic
In the last E@ :cripting article we saw so&e of the #asic features of E@ script. ,e are going
to learn a few &oreprogra&&ing concepts#efore we conclude our introduction series.
Conditional Statements:
/0 If statement:
'f 4condition5..Then
=Statement or a bloc$ of statement>
;lse
=Statement or a bloc$ of statement>
;nd if
This is the typical synta( to write this state&ent.
The if..then..else state&ents can #e nested to any nu&#er of levels.
lternately! the else #lock can #e used or not.
1lseif is another variation that can #e used when choosing #etween one of the
&ultiple options.
if x89 then
?sgbox 7value890
;lseif x81 then msgbox 7value810
;lseif x8@ then msgbox 7value8@0
;lse msgbox 7value not found0
;nd if
20 :elect state&ent
This is to choose one out of the &any options depending on the condition that co&es
satisfied. The condition is evaluated once and #ased on the value it attains one of the
following #locks of code gets chosen to #e run.
Select Case 4expression5
Case 7case1A
=Bloc$ 1>
Case 7case @A
=Bloc$ @>
C..
Case ;lse
=;lse bloc$>
;nd Select
Looping statements:
There are D $inds of loop statements1
/0 oGloop:
This is used when a state&ent or a #lock of state&ents need to #e e(ecuted while or until a
said condition is true. 2et us first look at the synta( of this.
/ynta& 0'
3o 4/hile E Fntil5 condition
=Statement or statements>
);xit 3o*
=Statement or statements>
&oop
/ynta& 1'
3o
=statement or statements*
);xit 3o*
=statement or statements*
&oop )=/hile E Fntil> condition*
$ondition. could #e a nu&eric or string co&ponent that either attains a true or false value.
If the condition is null it is treated as 0alse.
"#serve the 51(it do3 in the a#ove.
There is also a slight difference #etween the synta( * and synta( 7.
In case of synta( *! the state&ents within the do loop do not get e(ecuted unless! the
condition #eco&es true or holds true.
0or synta( 7! the state&ents within the loop get e(ecuted at least once and then the check
is perfor&ed on the condition.
1xit o: In order to avoid infinite loops we will have to force the loop to e(it. 1(it Do is a
state&ent that is used in such circu&stances.
20FhileGwend
/ynta&'
/hile
=Statement or bloc$ of statement>
/end
It is self e(planatory fro& the synta( that the state&ents nestled under the while #lock get
e(ecuted as long as the condition holds true.
lthough this state&ent is availa#le! it is not very fle(i#le so it is reco&&ended to use the
DoK2oop state&ent.
50 ?orG)ext
This is the state&ent that you would use when you want a state&ent<set of state&ents to
run a certain nu&#er of ti&es while a certain counter gets incre&ented or decre&ented.
%or counter 8 start To end )Step step*
)statements*
);xit %or*
)statements*
+ext
s you can see fro& the synta( a#ove! there is a 5:tep3 clause to this state&ent. This
clause is optional.
The step clause if not specified! the for loop steps one counter forward #y default
The step can #e used to incre&ent or decre&ent the counter value
1(it 0or is si&ilar to )1(it Do+! it can #e used to co&e out of the 0or #lock and
e(ecute the state&ent that follow.
ny nu&#er of 1(it 0or state&ents can #e used within one #lock of 0or state&ent
It is usually used with a if..then state&ent to &ake sure so&e condition that would
lead to infinitely looping is true and in case if it does! the 0or state&ent has a way to
e(it.
ny nu&#er of 0or state&ents can #e nested within a 0or.
2&ample'
''''''''''''
%ori81to 19
CC
'f x8true then
CC
;xit for
;nd if
+ext
2&ample for a positi#e step'
%or i 8 @ To 1@ Step @
total 8 total G $
+ext
2&ample for a negati#e step'
%or i 8 1@ To @ Step -@
total 8 total G $
+ext
-0 ?or eachGnext:
This is si&ilar to 50or Kne(t3. This is used for collection o#$ects or arrays. This state&ent
runs a state&ent or a set of state&ents for every o#$ect or ite& in an array instead of a
nu&#er of ti&es specified. s the 50orKne(t3 state&ent 1(it for is used to e(it #efore the
looping is through! like in case of an error. lso! any nu&#er of 0or 1ach state&ents can #e
nested within each other.
/ynta&'
%or ;ach element 'n group
)statements*
);xit %or*
)statements*
+ext )element*
1le&ent is the varia#le that is used to iterate through the ele&ents in the array or
collection o#$ect
group stands for the na&e of the collection o#$ect or array
)ote: ,e have not discussed collection o#$ects so far in our series! #ut a collection o#$ect
is nothing #ut an o#$ect which is a set of related ite&s Fo#$ects! these &ight #e of the sa&e
type or could #e of different typesG
Best Practices for Code Writing in VB Script
*. In the #eginning of every progra&! write down a #rief description of what the
progra& does
7. Provide co&&ents for every varia#le used during its declaration to #riefly descri#e
what this varia#le is going to do
4. Keep the code &odular! as &uch as possi#le
A. %ave the &ain progra& reada#le and have all the logic segregated in ter&s of
function! so it &akes the& easy to read and &aintain.
H. The segregation of code into functions will also increase reusa#ility
I. n agreed na&ing convention has to #e used to &aintain consistency
S. 8o&&ents > Provide co&&ents to &ake the code &ore understanda#le
C. Indentation > /ake sure that you indent the lines of code to clearly understand the
sequence of e(ecution
N. "ption 1(plicit is to #e declared so that you don3t run into issue when you have a
spelling &istake of a varia#le na&e
*D. ,atch out for infinite loops
Conclusion
This concludes our #rief introduction to E@ :cript. s already &entioned! this is in no way a
co&plete guide to learning the scripting language! #ut enough to get us through writing
#eginner to &oderate level QTP progra&s. There is one topic of functions that we did not
cover here #ut that e(clusion was deli#erate. It is #ecause! functions is a full length and a
very i&portant topic which we will discuss in detail in the co&ing articles.
11-QTP Password tool:
0or o#vious reasons we#sites do not display password even while we are providing it as an
input to sign in. QTP has a unique feature that will preserve the password fro& #eing out in
the open thus &aintaining the password3s integrity. s you &ight have noticed when we
enter the password as 5/ercury3 in the flights application a long and illegi#le sequence of
characters is set in the password edit #o(.
This is how it loo$s1
3ialog45Login67%8in2dit45+assword'67%/et/ec"re
5901c9:cda;<=a0;c>0aa9?<f;a0a<a9;;d(d>=e<@
In the a#ove line of code we can see that the password is encrypted.
QTP records a 5:et:ecure3 &ethod when a password is entered. It auto&atically encodes the
password entered during login and decodes the sa&e while running the test.
This is a &echanis& that QTP e&ploys to hide the password on the screen.
The user can also choose to enter a value discreetly into a non'password te(t #o( #y using
the :et:ecure &ethod and a encrypted equivalent of the te(t to #e entered as a para&eter.
If a need arises that we need to set a secure value in a certain te(t #o( then QTP co&es
with a tool called 5Password 1ncoder3. This tool will take a regular te(t and encodes it.
The )Password 1ncoder Utility3 is availa#le at.
/tart A +rograms A H+ *"ic$Test +rofessional A Tools A +assword 2ncoder
It launches the following app.
The tool is very user'friendly and self e(planatory.
,hen the )Password+ field is provided with an input! the )Generate+ #utton #eco&es active
and on clicking it! the encoded te(t is displayed in the )1ncoded :tring+ field. The sa&e can
#e copied to the clip#oard #y clicking on the )8opy+ #utton which gets ena#led when the
encoded password is generated.
0or e(a&ple.
8lick Generate.
The encoded te(t can #e used as a direct input to a te(t<edit #o( or as a para&eter in the
DataTa#le.
Active Screen:
This is another versatile feature that QTP provides to &ake thetesting process &ore
transparent to the user. ,hile recording QTP saves a snap shot of the application state
when a certain operation was perfor&ed on it. The a&ount of details that you want your
active screen to store and record depends on the settings. @efore we talk &ore a#out the
settings and what it &eans let us take a look at how the active screen looks.
To #iew the acti#e screen, clic$ on 5!iew)ABcti#e /creen6%
%ere I have a test that creates a G&ail account and I chose to view the active screen. This
is how it looks.
)Clic$ to enlarge image*
s you can see! when I have the state&ent selected the corresponding o#$ect on which the
state&ent acted upon is highlighted in the snap shot that the active screen has captured.
2et us see what happens when I &ove to the ne(t state&ent! FClic$ to enlarge imageG
The corresponding te(t #o( where I a& trying to enter the 0irst ?a&e is highlighted and as
it can #e noted this is no longer the G&ail page! it is the 5create a new Google account3
page.
?ow let us see what how &uch of infor&ation can we ask QTP to store in this snap shot
while recording and how do we do it.
Choose 5Tools)AOptions)ABcti#e /creen6 from the menu. 't opens up the following
window1
1ach level of capture and its corresponding features are e(plained in this window. The
default setting is as you see it in the screen shot.
The levels can #e changed as required.
The followin# are the levels and what each level means #ets displayed as the user
sets them.
*. 8o&plete
7. PartialFDefaultG
4. /ini&u&
A. ?one
The capture level can #e decreased or increased even after a test is created.
''''''''''''
lternately the user can set a custo& level of active screen capture #y clicking on the
)8usto& 2evel+ #utton and choosing the relevant options.
The active screen! apart fro& #eing a visual aid at e(a&ining process also has several
i&portant aspects that can help the tester to &anipulate the tests as required.
*. The "#$ects in the ctive screen can #e added to the local or shared o#$ect
repositories.
7. 8heck'points can #e added fro& this screen.
4. "utput values can #e added
A. Para&eteri;ation for the fields can also #e done fro& this screen
H. :teps can #e added to the test
0or e(a&ple! in our G&ail page earlier if I choose to add the 5:ign in3 #utton to the
repository I can do that #y right clicking on the o#$ect and the following options get
displayed for &e to choose fro&. FClic$ to enlarge imageG
s you can see! I can insert a checkpoint! output value or choose to view or add o#$ect
a&ong other things.
lthough we are yet to uncover the checkpoint and output value features! it is inevita#le to
&ention the& here! as they are so&e key functionality that the active screen helps with.
,eplacin# the active screen for a certain step:
In case a need arises for &e to change the active screen that got recorded #y default! QTP
provides &e a way to do that.
8hoose the option )Tools'68hange ctive screen+ fro& the &enu and QTP lets you go to the
new screen and when you click on the new screen! the control goes #ack to QTP with the
following confir&ation &essage. FClic$ to enlarge imageG
"n choosing )Oes+ to this &essage! the new screen will #e displayed hence forth when
active screen for that step is viewed.
If all the snap shots in your test have to #e replaced or updated! you can choose to run the
test in )Update =un &ode+. Oou &ight #e a#le to guess what this &eans! #ut in any case we
will have a detailed discussion on it later on in the co&ing articles.
.eal time use of active screen is when you want to ma$e changes to the test without
opening your application but 6ust from the screen captured during record.
lthough it &ust #e noted that tests with ctive screen captured occupy way &ore disk
space than the ones without it.
"n saving a test using ):ave as+ an option to e(clude ctive screen is availa#le to the user.
:o what you can do is! record a test with active screen! &odify it as needed while leveraging
as &any features as you can fro& it and ):ave as+ a new test without the active screen.
This ensures that your tests are easy on disk space at the sa&e ti&e you get to use the
active screen to your #enefit while it was needed.
That is so&e #rief insight into the topics! password encoder and ctive screen.
/2- 1xpert view of QTP >
1(pert view is where the operations we perfor&ed on the UT get displayed as E@
:cript code.
0or every 2"8 in this view! there is a corresponding colu&n in Keyword view.
There is also the action drop down #o( that can #e used to access! view and edit
different actions in the test.
This view is particularly useful for users who are fa&iliar with progra&&ing using E@
script.
"ne of the &ost i&portant uses of this view is that it facilitates the creation of
functions and function li#raries. Fa topic for detailed discussion laterG
The user can print the test or function li#rary as it appears in this view any ti&e.
0ile'6Print will print the test.
This is how it loo$s1
Oou can add state&ents to this view directly #y typing in or #y using step generator.
Step generator:
This is a facility that QTP provides in order to &ake adding progra&&atic steps into
QTP easy for the user.
Oou can use it in the Keyword view! function li#rary! ctive screen or 1(pert view to
generate steps
It can #e used to write steps into a test or to a function li#rary.
To launch! use the &enu option )Insert-!'tep Henerator+ &enu option. =ight click
any where you want the step to go and select )Insert 'tep-! 'tep #enerator+
or ?BFe(cept in ctive screenG
1xample:
I will e(plain this with a scenario. "pen www.g&ail.co& and click on )8reate ccount+ link.
This is how this state&ent will look.
*rowser(";mail: Email !rom ;oogle").Page(";mail:
Email !rom ;oogle").Lin.("-reate an
account").-lic.
If I need to check if the link e(ists at all! #efore I write the code to click on it! I will need a
step #efore the a#ove state&ent. This is how I do it.
'tep I /0 :elect the place where you need the step inserted.
a0 1(pert view. Place the cursor where you want the step to go and launch step generator.
%0 Keyword view. :elect the step #elow which you want to insert the step.
c0 ctive screen. In the active screen window! right click and choose the step generator
option. It will ask you to choose the o#$ect on which your step should #e #ased on.
0ollowing that the step generator window is launched.
'tep I20 This is the step generator window that gets launched. Please note the details that
it is displaying now. It is showing all the details related to the step that is currently chosen.
,e can choose the required values for the new step #ut that does not affect the current
step.
I a& going to set the values as required #y &e to ena#le checking if the link e(ists.
s you can see! I chose a Test "#$ect! 8reate an account link and chose the operation 1(ist.
I left the argu&ents e&pty #ecause it is optional and chose that the return value of the
operation #e stored in a varia#le varU1(ist. It displays the E@ :cript state&ent! as it is going
to appear in the 1(pert view in the )Generated :tep+ field. In other words! the synta(.
'tep I50 The drop down where I chose a test o#$ect! I can alternately choose to #ase &y
step on a utility o#$ect or 0unctions.
'tep I-0 "#$ect. this field contains a list of required o#$ect or the function li#rary source.
'tep I30 "peration field will let you choose the appropriate &ethod! property or function.
''''''''''''
'tep IA0 rgu&ents and =eturn value. These fields are self e(planatory. The user could
para&etewise the argu&ents or provide constant values.
'tep IB0 The user can $ust insert one state&ent or choose to follow it with another one #y
checking the )Insert another step+ option "?.
'tep I>0 :o! #ack to our e(a&ple. I will click "K. This is the state&ent that gets inserted.
6ar<E/ist 1 *rowser(";mail: Email !rom
;oogle").Page(";mail: Email !rom
;oogle").Lin.("-reate an account").E/ist
*rowser(";mail: Email !rom ;oogle").Page(";mail:
Email !rom ;oogle").Lin.("-reate an
account").-lic.
Checkpoints
,e have so far encountered in various places of your articles! so&ereferences to
checkpoints. There are &any ways to define what a checkpoint is! this is &ine >)'t is a
logical point in your test where you are trying to establish if there is a match between a
certain expected value to the actual value as it exists on the (FT+.
,e have talked earlier9 QTP provides certain in#uilt checkpoints #ut does not li&it the user
to $ust those. t any point in a test! the tester is free to #uild any nu&#er of check points in
his test to include verification points. That according to &e is one of the &ost versatile
features in QTP.
It is o#vious that custo& checkpoints are entirely relative to each one3s pro#le& at hand.
,e will equip ourselves with #asic concepts on the checkpoints that co&e as an integral part
of QTP.
*G ,hen a checkpoint is added! QTP adds a )$hec& $hec&Point@ in the 1(pert view and a
corresponding row in the keyword view.
1xample:
*rowser(";mail: Email !rom ;oogle").Page(";mail:
Email !rom ;oogle").-3ec. -3ec.Point(";mail: Email
!rom ;oogle")
20 The user can have the check point state&ent return a #oolen value that depicts the
result of the checkpoint. If it passed! it returns a * and D if failed. To #e a#le to that! we
need to use parentheses around the checkpoint argu&ent in the state&ent in the 1(pert
Eiew.
1xample:
i1*rowser(";mail: Email !rom
;oogle").Page(";mail: Email !rom
;oogle").-3ec.(-3ec.Point(";mail: Email !rom
;oogle"))
50 @y default! the na&e of the checkpoint will #e the na&e of the o#$ect on which this
check is perfor&ed.
-0 The user can accept this na&e or change it
30 ,hen the test runs! if the e(pected value &atches with the actual one for the
checkpoint! the checkpoint passes otherwise it fails.
A0 The results can #e viewed in the =un =esults viewer.
There are /D chec&points that QTP provides to its users:
*. :tandard 8heckpoint
7. I&age 8heckpoint
4. @it&ap 8heckpoint
A. Page 8heckpoint
H. Te(t 8heckpoint
I. B/2 8heckpoint
S. Te(t rea 8heckpoint
C. Ta#le 8heckpoint
N. ccessi#ility 8heckpoint
*D. Data#ase 8heckpoint
The general way a checkpoint is inserted is after the initial test steps are created. It is
possi#le to add checkpoints during recording or editing though.
It is recommended that the tester has preliminary &nowled#e a%out all the
chec&points in order to ma&e the ri#ht +ud#ment a%out what chec&point is apt for
the tas& at hand.
In the previous QTP training session we listed all the checkpoints that QTP provides. ll
these checkpoints are very i&portant to insert verification points in QTP tests to check if
current and e(pected values of an o#$ect &atch or not. This deter&ines the P:: or 0I2
status of that test.
.
13-Standard Checkpoint:
/0 It is used to check the "#$ect Property value.
20 8o&pares the e(pected value with the actual value during runti&e.
50 It can #e set during recording or editing a test.
-0 ctive screen can also #e used to insert this checkpoint. It is i&portant that sufficient
infor&ation #e availa#le in the active screen to #e a#le to insert a checkpoint.
For 2&ample' If there is a screen with! 2ogin edit #o(! Password 1dit #o(! "K! 8ancel
and %elp #uttons. ,e need to check if the 8ancel #utton is visi#le. ,e are trying to achieve
this #y placing a checkpoint on the )Eisi#le+ o#$ect property of the 8ancel #utton. ,hile
recording I perfor&ed a enter 2ogin! enter password and click "K9 and the setting on &y
active screen is to $ust store the o#$ects I acted on and not the others! I will not #e a#le to
place the checkpoint on the cancel #utton #ecause the active screen does not possess
infor&ation a#out that o#$ect. Therefore! it is i&portant for the active screen to have
captured all the o#$ects in the page and only then we can insert the checkpoint. I hope this
e(plains what I &ean when I say that the active screen should have sufficient infor&ation.
30 "nce added! the checkpoint properties can #e changed using the )8heckpoint Properties+
dialog #o(.
A0 1very checkpoint gets added to the local o#$ect repository when added. It can #e &oved
to the shared o#$ect repository if needed.
B0 :upported for all the environ&ents as long as the appropriate add'ins are loaded.
>0 :o&e e(a&ples of the o#$ects that this can #e used on are. we# i&ages! 1dit #o(es!
static te(t! we# ta#les etc.
*ow to insert a standard chec&point while recordin#:
'tep I/0 Insert'68heckpoint. :elect this option fro& the &enu after starting a record
session.
'tep I20 > 8licking on this icon also results in the sa&e thing.
'tep I50 list of relevant checkpoints applica#le to the current or selected step on
perfor&ing one of the steps listed in * and 7.
'tep I-0 :elect the type of checkpoint. ,e will select ):tandard+ in our case.
'tep I30 QTP interface gets hidden and the user can choose the o#$ect in the UT over
which the user wants to insert a checkpoint.
'tep IA0 :elect the o#$ect and the following screen appears.
'tep IB0 8hoose the o#$ect and click "K in the dialog. The checkpoint properties dialog
#o( is displayed.
'tep I>0 :elect the properties you want checked and click "K. I a& going to choose $ust
the na&e. s you can see a#ove! you can &odify the properties to to either a constant
value or para&eteri;e. There is also a ti&eout para&eter that you can set. ,hat this &eans
is that! QTP waits for the particular nu&#er of seconds specified in this dialog for a certain
"#$ect to attain a property value #efore it perfor&s the check.
'tep IC0 This is how I set the para&eters and click "K.
'tep I/D0 This is how &y checkpoint looks in the keyword view.4clic$ to enlarge
image5
'tep I//0 In the e(pert view! the following code gets displayed.
1
*rowser(";mail: Email !rom ;oogle").Page(";mail: Email !rom ;oogle").We$*utton("Sign in").-3ec.
-3ec.Point("Sign in<")
*ow to insert a 'tandard chec&point while editin#:
/0 "ctive 'creen: In the active screen! right on an o#$ect and select the option to insert
standard checkpoint. fter that! follow the sa&e steps as a#ove to insert a
checkpoint. 4clic$ to enlarge image5
''''''''''''
20 t any step in the QTP test! select the &enu option )Insert'68heckpoint+ and choose
):tandard checkpoint+. gain follow the steps as a#ove.
*ow the chec&point properties can %e accessed and modified
fter creation! the user can &odify a checkpoint as required. This can #e done through the
)8heckpoint properties+ dialog #o(. This dialog can #e accessed in the following ways.
/0 ,hile creating a checkpoint this #o( opens up for initial definition of the properties
20 :elect an e(isting checkpoint state&ent in the Keyword view! right click and select
)8heckpoint properties+
50 "pen the "#$ect repository and the properties are availa#le there are shown
#elow. 4clic$ to enlarge image5
0ro& this #o(! all the properties of a checkpoint can #e &odified as required.
:ince the standard checkpoint is the first in our list I have provided the detailed steps of
adding it in different scenarios and &odifying it in different ways in detail. /oving forward I
a& going to list the properties and features that are unique for each checkpoint. It should
#e noted that the steps to add! use and &anipulate the checkpoints are all the sa&e for
&ost of the checkpoints. 0ro& now on! unless specifically &entioned! the a#ove approach
can #e used generically across the other ones too.
Image Checkpoint:
slight variation of a standard checkpoint is while it is used on we# i&ages.
In case the o#$ect on which the checkpoint inserted happens to #e a we# i&age! the
following dialog #o( opens up.
It should #e noted that this screen is al&ost identical to )8heckpoint Properties+ dialog! it is
specific to i&ages.
The only e(tra para&eter is the )8o&pare I&age 8ontent+ check#o(. If it is checked! the
i&age in run ti&e is checked with the one stored during the creation of the checkpoint to
see if it is e(actly the sa&e. If they are the sa&e! the test results will only have one i&age.
If they are different #oth the i&ages will #e displayed in the test results.
0or e(a&ple! on the g&ail page! I tried to insert a standard checkpoint on one of the
i&ages fro& the ctive screen and this is what gets displayed. 4clic$ to enlarge image5
I will not &ake any changes in the dialog! you can if you wish to and click "K.
This is how the inserted checkpoint is going to #e. 4clic$ to enlarge image5

Vous aimerez peut-être aussi