When we have to define variables, try to use the following suggested 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
Variable Definition
Number
nExchRate
Unlike VBA and other programming languages, QTP does not use classes, methods, etc. QTP can use actions, which can receive and send data through parameters.
As a suggestion, we can try to create a test, called "Resources", in which actions are included with most objects used during our tests.
We must ensure that actions are created are reusable, so the we can use whenever you need them.
This will prevent grab code every time we need to automate and maintain order in our test scripts.
Every time we need any of the actions we have recorded, only need to invoke it from another test.
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 action related to the datasheet and has the distinction of not being editable.
Using Functions
If you are in the need to reuse the same piece of code in a single action, you should try to use a function to reduce the lines of code.
Unnecessary code
When recording the actions we want to automate, QTP usually record everything we do, even when the mouse passes an object. Whenever we debug our code and delete those lines. This will help us to reduce the runtime of our scripts.
Comments
We should always try to start each script with a small comment, 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 I
update the script. References: Indicate the WTs related to the script
Comments
e.g.
Comments - Checkpoints
When we add a checkpoint, we should try to insert a comment on the following line to indicate a brief reference to the related WT or an explain for the checkpoint. Having our code documented allow us to edit without the need for some explanation.