2) Random number parameters
3) Environment variable parameters
4) Test/Action parameters
#2 – QTP Parameterization using Random Number
If a certain field needs to have any number within a certain range you can specify the same using QTP. In the Value configuration properties screen, select “Random number” and the following options come up:As you can see, the options are pretty self explanatory. The range can be set and how many times during a particular iteration run or a test run should this value be generated can be programmed here.
Let us just keep the default settings and click OK and see the line of code that gets inserted.
1
| Browser( "Google" ).Page( "Google" ).WebEdit( "q" ). Set RandomNumber( "p_Text" ) |
#3 – QTP Parameterization using Environment Variables
Environment variable is a value that remains the same throughout a test run unless explicitly changed by the program.3 types of environment variables:
- User defined internal
- User defined external
- Built in
Built in variables are created by QTP itself and contain information about the test path, operation system etc. These are read only and hence can only be used by the user as they are.
Some examples are TestIteration, OS, OSVersion etc. The usage is similar to the usage of any other variable. For example in the second iteration of a test you want to display a custom message, this is how you can do it:
1
2
3
4
| If TestIteration=2 Msgbox “Cusotm message: Take a break!” <….Code….> End if |
From the above screen, you can see that the type is read only and we are only able to create a user defined- internal environment variable.
Click on the “Name” Drop down box:
Even though we have not created any environment variables in this test so far there are many of them available in the drop down to be used.
Select any one of them:
It shows that the variable is a built-in and read only. So this shows how we can use a built in variable.
But if we need a new one, enter a new name, say PV assign 0 and save it:
Let us first accept the default values and enter a “0” in the value field and click OK. The following is the line of code that gets inserted:
1
| Browser( "Google" ).Page( "Google" ).WebEdit( "q" ). Set Environment( "PV" ) |
User defined – external: In case when we need to have an entire list of environment variables available for a test, the user has an option to create it externally and associate it to the test and make those variable available to this test.
Typically, this file is an .xml with the structure as follow and is available on your desktop:
1
2
3
4
5
6
7
8
9
10
| < Environment > < Variable > < Name >First Name</ Name > < Value >Swati</ Value > </ Variable > < Variable > < Name >Last Name</ Name > < Value >Seela</ Value > </ Variable > </ Environment > |
In the screen, you can see the option to add the file, so ahead and add it.
Alternately, if I need the variables in this test for another one, I can export them into a file by clicking on “Export” option.
So now that we know how to set and use environment variables, there is yet another use for these:
In case, we set the values for URL_env and Browser_env variables, then the record and run settings set overrun and no matter what you set there, it is going to consider the values that these variables contain.
#4 – QTP Parameterization using Action and Test Parameters
We know that a test in QTP but a call to an action. Input parameters for an action or test are nothing but the values that get supplied to them from else where in the test.They could be:
- Value(s) passed on while calling that action
- Return value of another action (Output parameters)
- A value that it gets from some top level action
The way these can be used to parameterize is as follows:
These can be used as a parameter by using the “Parameter” keyword.
If this is the statement that you need to parameterize so that the value you set is not a constant “swati” but a value that is the input value of an action that is already defined, say “OPFirstName”:
1
| Browser( "Gmail: Email from Google" ).Page( "GoogleAccounts" ).WebEdit( "FirstName" ). Set "swati” |
1
| Browser( "Gmail: Email from Google" ).Page( "GoogleAccounts" ).WebEdit( "FirstName" ). Set Parameter(“OPFirstName”) |
1
| Parameter( "TotalValue" ) = Browser( "Gmail: Email from Google" ).Page( "GoogleAccounts" ).WebEdit( "FirstName" ) |
You can define, modify, and delete input and output parameters in the Parameters tab of the Action Properties dialog box (Edit > Action > Action Properties or right-click an action and select Action Properties).
Similarly, for the test, the parameters can be set:
So, to call an action with the input parameters this is the statement that needs to be used:
1
| RunAction ActionName, IterationQuantity, Parameters |
Also don’t forget to check all QTP tutorials on this page as well.
No comments:
Post a Comment