qtp - programming tips
TRANSCRIPT
-
8/3/2019 QTP - Programming Tips
1/13
-
8/3/2019 QTP - Programming Tips
2/13
Variable Definition
When we have to define variables, try to use the followingsuggested format:
tXxxxxx
t: means the character that indicates the data type of the variable.
Xxxxxx: Variable name in English, the first letter capitalized
e.g.
dStartDate, sDocType, sDocNumber, nExchRate
-
8/3/2019 QTP - Programming Tips
3/13
Variable Definition
The most used data types in QTP are:
Type Example
String sDocNumberBoolean bIsTrue
Date dStartDate
Number nExchRate
-
8/3/2019 QTP - Programming Tips
4/13
Using Actions in QTP
Unlike VBA and other programming languages, QTP doesnot use classes, methods, etc.
QTP can use actions, which can receive and send datathrough parameters.
-
8/3/2019 QTP - Programming Tips
5/13
Using Actions in QTP
As a suggestion, we can try to create a test, called"Resources", in which actions are included with most objectsused during our tests.
-
8/3/2019 QTP - Programming Tips
6/13
Using Actions in QTP
We must ensure that actions are created are reusable, sothe we can use whenever you need them.
This will prevent grab code every time we need to automateand maintain order in our test scripts.
-
8/3/2019 QTP - Programming Tips
7/13
Using Actions in QTP
Every time we need any of the actions we have recorded,only need to invoke it from another test.
-
8/3/2019 QTP - Programming Tips
8/13
Using the DataTable
To read data from the DataTable, we generally use thefunction:
DataTable.Value(Columna,hoja)
We must seek to use this function as follows:
DataTable.Value(Columna, dtGlobalSheet)
The data is on the "Global" sheet, this data is used by various actions
and has the distinction of being editable.
DataTable.Value(Columna, dtLocalSheet)
The data is on the Local" sheet, this data is used only by the actionrelated to the datasheet and has the distinction of not being editable.
-
8/3/2019 QTP - Programming Tips
9/13
Using Functions
If you are in the need to reuse the same piece of code in asingle action, you should try to use a function to reduce thelines of code.
-
8/3/2019 QTP - Programming Tips
10/13
Unnecessary code
When recording the actions we want to automate, QTPusually record everything we do, even when the mousepasses an object. Whenever we debug our code and deletethose lines.
This will help us to reduce the runtime of our scripts.
-
8/3/2019 QTP - Programming Tips
11/13
Comments
We should always try to start each script with a smallcomment, describing the script.
As a standard, we should try that in the commentary
provides the following information:
Title: Description of the script
Last Update: Date of last update, could be the last release which Iupdate the script.
References: Indicate the WTs related to the script
-
8/3/2019 QTP - Programming Tips
12/13
Comments
e.g.
-
8/3/2019 QTP - Programming Tips
13/13
Comments - Checkpoints
When we add a checkpoint, we should try to insert acomment on the following line to indicate a brief reference tothe related WT or an explain for the checkpoint.
Having our code documented allow us to edit without theneed for some explanation.