By the end of reading this topic you will be able to answer the following questions:
1. What is parameterization?
2. How many types of parameters are there in QTP?
3. What is difference between Test and Action Parameters?
4. What are Environment Variables?
5. In how many ways can data table parameterization be done?
Parameterization is a process of replacing hard coded/fixed values with multiple values in order to expand the scope of the test.
There are four types of parameters in QTP.
a. Test/Action parameter
b. Data table parameter
c. Environment variable parameter
d. Random number parameter
Test/Action Parameters:
Test Parameters are those which are passed across a test globally. These can be used by any action/actions present in the test. Action Parameters are those which are passed from one action to other action. These can be used only across the passed actions. These are again divided into types:
1. Input Parameters
2. Output Parameters
Input parameters specifies the parameters that the test/action can receive values from the source that runs or calls it. In short input parameters pass values into your test.
Output parameters specifies the parameters that the test/action can pass to the source that runs or calls it. In short output values passes values from your test to external sources.
To define Test Parameters go to Test-->Settings-->Parameters Tab.
To add a new parameter click on '+' button. To delete existing parameter in the list, select the parameter and click on 'X' button.
To add parameters, click on Add('+') button. Go to the name box and add a name to the parameter. This is a required field. It should be kept in mind that name field is case sensitive.
Select the type of parameter from type drop down. Type drop down provides a list of parameter types such as string, Boolean, date, number, password and Any. This is also a required field.
Enter some default value to the parameter in Default value box. The default value is required to run the test if no value is received from test.
Description is an optional field. This field is used to enter some description about the parameter.
To define Action Parameters go to Edit-->Action-->Action Properties-->Parameter Values Tab.
Adding action parameters would be the same process as how it was done for Test Parameters.
Now it is clear where to add parameters for Test/Action Parameters. Now the question is how to use them in the script?
Let's discuss usage of these parameters in a script with a small example:
Assume that Action3 is called from Action2. Following would be a normal statement for calling action3 from action2:
RunAction "Action3", oneIteration
RunAction "Action3", oneIteration
The same statement with one input parameter and one output parameter would like:
RunAction "Action3", oneIteration, input1, output1
Note: While passing input and output parameters in the same statement, input parameters are given first in the statement and then output parameters follows. See the following statement:
RunAction "Action3", oneIteration, input1, input2, input3, output1, output2
As discussed above here input 1, input 2 and input 3 are the values that are passed to the action 3 and output1, output2 would be the values received from Action3 to Action2.
Now open Action3 and add input1, input2, input3 in input parameters section and output1 and ouput2 in Output parameters section.
Now to access input1, input2 and input3 values in Action3 we have to use Parameter Object in Action3.
Value1=parameter("input1")
Value2=parameter("input2")
Value3=parameter("input3")
Now Value1, Value2 and Value3 present in Action3 will have values that are passed from Action2 and these can be used across Action3.
And after executing some series of statements in Action3 assume that you got the results that needs to be sent back to Action2 and assume that those results are stored in variables opvalue1, opvalue2. Now as you have already defined parameters output1 and output2 in output parameters section of Action3, just use the following statements in Action3:
parameter("output1")=opvalue1
parameter("output2")=opvalue2
After Action3 gets executed and returns back to Action2, it gets returned along with the values that are passed from Action3 to Action2.
Data Table parameters:
Data Table parameters enable you to create a data-driven test, or action that runs several times using the data you supply. i.e., for every iteration, qtp takes a new value from data table.
Assume that User name and Password fields in Login page should be tested with different sets of test data, then instead of creating script for each set of data, we just create a script with one set of data and parameterize the User name and password fields so that qtp while running picks values for each iteration from data table.
Assume that following are the statements generated while logging into gmail:
Browser("Gmail").Page("Gmail").Webedit("Username").Set "user1" Browser("Gmail").Page("Gmail").Webedit("password").Set "password1" Browser("Gmail").Page("Gmail").Webbutton("Sign In").Click
After parameterizing, the same script would like this:
Browser("Gmail").Page("Gmail").Webedit("Username").Set datatable("username", dtlocalsheet)
Browser("Gmail").Page("Gmail").Webedit("password").Set datatable("password", dtlocalsheet)
Browser("Gmail").Page("Gmail").Webbutton("Sign In").Click
And the data table would look like:
Data table Parameterization can be done in following ways:
- Parameterizing through expert view
- Parameterizing through Keyword View
- Parameterizing through Data driver wizard
- Parameterizing through Object repository
For detailed information on Data table parametrization, please see "Data table parameterization in QTP" topic.
Environment variable parameters:
Environment variable parameters:
Environment variables are again internally divided into two types. They are:
1. User defined variables
2. Built in Variables
These variables can be defined in Tools-->Settings-->Environment Tab.
1. User defined Variables: These variables enable us to use predefined data from other sources during run session. These can be globally used across different tests or can be restricted to use only for current test.
2. Built in Variables: These variables enable us to use information about the test and the computer on which the test is run such as Action iteration, Action name, operating systems version, Local host name etc.,
For detailed information on how to define values in Environment Variables, please read "Environment Variables in QTP" topic.
Random Number Parameter:
These parameters enable us to insert random numbers as values in our test. For example when we want to open an order randomly we can use the following function to generate an order number:
Orderno=int((100*rnd)+1) ' Randomly picks a value from 1 to 100. As QTP count starts with 0, number one is added in the function to pick the number from 1.
Reference: Quick test user guide - Parameterizing values
No comments:
Post a Comment