In this LoadRunner tutorial, we will discuss ‘LoadRunner Parameterization’ – Creating and configuring parameters, types of parameters and their real time use etc.
In the last tutorial, we discussed that a VuGen script can have two types of data/values that we may
need to handle:
- Static values: The values that a user enters. Ex. Username, password, credit card details etc.
- Dynamic values: The values that are generated and sent by the server. Examples are session ids/tokens, session states, date values etc.
In this tutorial, we will discuss more on static values and learn how to parameterize them.
When we recorded our Web Tours application to create the script, we used static values like username, password, credit card details etc. While running the script the same values will be used by every Vuser as it is with a huge number of Vusers.
This is not realistic as all the users in the real world do not input the same values. Hence, we have to parameterize the input values.
What You Will Learn:
Parameterization in LoadRunner
Now let’s see how we parameterize the data values.
Example: If we want to parameterize the username value in our script, select the value, right-click and select ‘Replace with Parameter’ -> ‘Create new parameter’.
Enter the parameter name. We can enter any name here (we have added the prefix ‘par’ just for our convenience – which means this is a parameterized data).
Next, VuGen will prompt for this.
Click ‘Yes’. VuGen will replace all occurrences of the username value with the parameter as shown (remember parameters are always enclosed in curly braces).
Now, in order to view the parameter(s) that we created, click on ‘Parameters’ item on the ‘Solution Explorer’.
This will open the parameters list window. This list will show the username parameter that we created.
The parameter name is ‘parUserName’ (the parameter name that we entered), the parameter type is ‘File’ (this is the default parameter type – we will discuss the other types of parameters later in this tutorial) and the parameter file name is ‘parUserName.dat’ (parameters are generally stored in a text file that is saved in the script folder, by default the name of this text file is the parameter name itself).
We can also create the parameters from the ‘Parameter List’ window directly. Just click on the ‘New’ button on the bottom left.
The new parameter is added to the list.
Rename the parameter name to say ‘parPassword’, select the parameter type (default is File), choose the file name and path.
Now click on ‘Create Table’.
We can now see and edit the values for this parameter (note that this file has one column and the default name of the column is the parameter name itself).
Example: Here we have changed the value to ‘bean’.
We can also change the values in another way – click ‘Edit with Notepad’ button and edit the data in the text file directly.
In fact, this is the easiest way of editing the data, particularly when we are dealing with huge data, we can just copy and paste the required data, easily edit on the notepad and so on.
Now, let us add few more values for the ‘parPassword’ parameter.
Close the notepad and click on ‘Save’ (to save the changes made to the text file).
So the added values are reflected in the ‘Parameters List’ window (for the ‘parPassword’ parameter).
Remember that when we directly create parameters on the ‘Parameter List’ window, we have to manually replace all occurrences of the value in the script with parameter name (of course in curly braces).
So go to the search menu (Search->Quick Replace).
And make the replacement.
In the script.
One more thing to note is VuGen by default creates a new text file for each of the parameters created.
But we can also save more than one parameter value in a single text file by putting them under different columns separated by a delimiter (‘comma’ is the default limiter). This is done particularly for data values that are dependent (Example: username and password).
Let’s see how we can do that. We will put the username and password values in a single file. In the ‘parUserName’ parameter that is already created, change the file name to say ‘usercredentials.dat’ (this will create a new file with this name under the script folder).
Now open this file with a notepad, add two columns – username and password separated by a delimiter (comma here) and also add some values for username and password separated by the comma delimiter as shown below.
Now close and save the file.
Next, we have to link each parameter with the column names. This can be done from the ‘Select column’ section where we can link by the column name or column number.
Here we have linked the ‘parUserName ‘parameter to the first column of the text file ‘By number’.
We can also do the same with ‘By name’.
Now let us go to the ‘parPassword’ parameter, change the file name (to the ‘usercredentials’ file that we created).
And now we have to link the ‘parParameter ‘parameter to the second column of the text file (as the password values are in the second column) ‘By number’ or ‘By name’.
It is a good practice to use the column names as it will avoid confusion, particularly when we have a larger number of columns.
So far we have understood how to create multiple parameters and link them to the values in a single text file.
Coming to the other parts of the ‘Parameter List’ window, under the ‘File format’ section, we have two options:
Column delimiter: This allows us to select a delimiter when we use multiple columns in the text file. The comma is the default delimiter (as we saw above) but we can also choose the Tab or Space. This option is very useful in cases where the data itself has commas (Example: an address) and using comma delimiter can screw things.
First data line: This is used to specify which row to start with (default is 1). We can change it to any value (till the maximum number of values in the text sheet). Ex: If we change it to 3, VuGen will start picking from the third-row value (ignoring the first 2 data values).
This is useful when for some reason we don’t want VuGen to pick some data values and at the same time don’t want to completely delete them from the file.
The ‘Import Parameter’ option allows us to import data from an external file directly.
Click on ‘Import Parameter’ button.
Here we can select the file, specify the delimiter and configure the other options.
Now coming to two more important options:
Select next row: Instructs VuGen how to select the data values during the test when multiple Vusers are running (and each Vusers is running for multiple iterations). We mainly have three options here –Sequential, Random, and Unique.
Update value on: Instructs VuGen when to update the data values of the parameters. We have three options here –Each iteration, Each occurrence and Once.
The combination of these two options defines what values (from the data file) are to be taken by each Vuser for each iteration and each occurrence (within an iteration).
Let us understand each of these combinations in detail now:
a) Sequential-Each iteration: Every Vuser starts from the first data value in the text file and goes to the next row value in every new iteration sequentially. If there are not enough values in the file, Vuser returns to the first value in the file (continuing in a loop till the end of the test).
b) Sequential-Each occurrence: Every Vuser starts from the first data value in the text file and goes to the next row value in every new occurrence (within the iteration) sequentially. If there are not enough values in the file, Vuser returns to the first value in the file (continuing in a loop till the end of the test).
c) Sequential-Once: Every Vuser on every iteration and every occurrence (within an iteration) takes only the first value from the data file.
Example: Say we have five urls and for a particular test we want to use only one (of these five), in such a case we can set this option.
d) Random-Each iteration: Every Vuser takes a new random data value from the text file on every iteration. Here duplication of values is possible as the selection of values is random.
Example: If we have an application which generates sales report for a given month (Jan, Feb …… Dec), we can set this option so that Vusers pick one of these twelve months randomly and generates a report.
e) Random-Each occurrence: Every Vuser takes a new random data value from the text file on every occurrence (within an iteration). Here duplication of values is possible as the selection of values is random.
We can set this option for similar scenario (sales report) as explained above; the only difference is here Vusers will pick a random month on every occurrence.
f) Random-Once: Every Vuser takes a random data value from the text file on the first iteration and sticks to the same value for all iterations and occurrences.
Example: we have an application/scenario where a user has to randomly pick up a product (from a list) and work on the same product for all iterations and occurrences, we can set this option.
g) Unique-Each iteration: Every Vuser for every iteration takes the first unused (unique) data value from the text file.
We have some additional options available for this combination:
When out of values: Instructs a Vuser on how to handle the script when the values are exhausted.
We can select any of these from the dropdown list.
Allocate Vuser values in the Controller: This option is used to instruct VuGen to allocate a block of values (a group of values) for every Vuser. In this way, values will be unique to Vuser. The size of the block (number of values) can be specified by us or left to VuGen to calculate. For Example, if we have 100 values and 5 Vusers, we can allocate ‘20’ values per Vuser (as shown below).
Example: If we have an application/scenario where we have to use say discount coupon ids and these ids are unique to a user, under such cases we can use this option.
h) Unique-Each occurrence: Every Vuser for every occurrence takes the first unused (unique) data value from the text file.
Like with ‘Unique-Each iteration’, here also we will have the same additional options (only difference here is we have to mandatorily allocate block size here).
Example: If we have an application/scenario where we have to use say discount coupon ids and these ids can be used only once, we can use this option.
(i) Unique-Once: Every Vuser takes an unused (unique) data value from the text file on the first iteration and sticks to the same value for all iterations and occurrences.
Example: We can use this option for login details (username and password) because these have to be unique to every user.
One more thing – When we have parameters that are related, then we can set one of the above combinations for one parameter and direct VuGen to use the same for the other parameter(s).
Example: Here we set the ‘Unique-Once’ combination for the username parameter.
Now for the password parameter, instead of setting again, we can just select ‘Same line as parUserName’. This will instruct VuGen to just follow what was set for the username parameter.
Other types of parameters:
We discussed the default type – ‘File’ type of parameter already. There are other types of parameters as well and we can see them in the ‘Parameter type’ dropdown list.
Let’s discuss some of these now:
a) Date/Time: This type of parameter allows a Vuser to pick the current date and time in a specified format.
It also allows selecting a future date using the ‘Offset’ option.
It also allows selecting a past date using the ‘Prior to current date’ offset option.
b) Iteration Number: This type of parameter allows a Vuser to pick the iteration number in a specified format.
c) Random Number: This type of parameter allows a Vuser to pick a random number from a given range in a specified format.
d) Unique Number: This type of parameter allows a Vuser to pick a unique number by specifying a number range and block size per user.
e) Vuser ID: This type of parameter allows picking a Vuser id in a specified format.
We have a hands-on video tutorial recorded on the earlier version of the LoadRunner but the content still valid for the latest Micro Focus version.
Video Tutorial: Parameterization in LoadRunner
Video Tutorial Summary:
What is Parameterization?
- Replacing hard coded values in the script is called Parameterization.
- Parameterization helps in :
- Reducing script size
- Avoiding cache effect
Type of Parameters
#1. Date/Time – Whenever we have to replace a date value with a parameter, Date/Time parameter is used. Any post with past date is not valid. To keep it updated, Date/Time parameter provides flexibility to get the current or future date. If past date is needed, it handles that too.
#2. Group Name -We can generate a parameter on the basis of group that we select on controller for the script while execution. This parameter will only work while running the script on controller.
#3. Iteration Number – This replaces the parameter with current iteration number. This is generally used to build some logic. For example- when we want some code in script to be executed alternatively. For this, we will use the iteration number to check whether it is even or odd number and for one of the condition we will execute the function.
#4. Load Generator Name – We can also generate parameter while executing the script on controller on the basis of load generator name on which that script is running. This parameter only works while running the script on controller.
#5. Vuser ID – When we run the script on controller, it assigns a unique id to each virtual user that emulate during the execution. This parameter type is used –
- To print the Vuser ID in an external file for script-debugging purpose.
- To segregate transaction volume based on Vuser ID
#6. File – Some time we want to pass the specific value in the script. In such cases, we use file and enter the values that want to use during execution. LR provides options to run the script with provided list sequentially or randomly on next iteration.
In few cases we want to use a set of values passed to the script. In such cases, we can use same file for the other parameter value as well.
#7. Random Number – As per need, Vugen also generates random value from the provided range.
#9. Unique value – In few situations, script is not allowed to pass any duplicate value. In such cases, unique parameter is used to avoid failures due to duplicate value,.
#10. User Defined function – Such parameter calls a function whose return value replaces the parameter name.
#11. XML – XML Parameter Types are used for multiple valued data contained in an XML structure. XML parameters are widely used with Web Service scripts and with SOA services.
In this tutorial, we discussed ‘Parameterization’ in detail which included create and configure parameters, different types of parameters, options with respect to the ‘File’ type parameter and their real-world use.
We will learn more about Transactions, Text and Image Checks, Comments and Rendezvous points in our upcoming tutorial!