How to select a random parameter from a captured list using LoadRunner

When performance testing it is important to simulate realistic user journeys through an application. With this in mind it might be necessary to choose options at random from a list. In the example below which was used to performance test a share dealing application it was necessary to simulate the purchase of different shares so that all vUsers aren’t selecting the same share.

The lr_paramarr_random function can be use to simulate users selecting different items from a dropdown list.
First capture the parameter using a web_reg_save_param function, select all ordinal values using ORD=ALL.
LoadRunner Screenshot

In the example above the following values were captured.
Action.c(118): Notify: Saving Parameter “CompanyName_1 = BARCLAYS ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_2 = HBOS ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_3 = LLOYDS TSB GROUP ORD GBP0.25”
Action.c(118): Notify: Saving Parameter “CompanyName_4 = TESCO ORD GBP0.05”
Action.c(118): Notify: Saving Parameter “CompanyName_5 = VODAFONE GROUP ORD USD0.11428571
The lr_save_string function is then used to save one of the “CompanyName” parameters into a new parameter called “RandCo”.

LoadRunner screenshot

e.g.
Action.c(154): Notify: Parameter Substitution: parameter “RandCo” =  “HBOS ORD GBP0.25

LoadRunner Date/Time Functions

LoadRunner stores date/time parameters locally on the LoadRunner PC. This means that opening a script on another users PC, where the date/time parameter is not stored, can cause corruption to the date/time parameters in a script. You know that this has happened when a date/time parameter in this format [%Y%m%d%H%M%S] is sent to the server rather than the format that you intended.

Due to this problem, I recommend that the lr_save_datetime function is used to save date or time values to a string. The string can then be used in the script and the script is portable between PCs because we are no longer relying on the locally stored parameters.

Sample code

lr_save_datetime(“%d/%m/%y”, DATE_NOW, “DDMMYY”);
lr_output_message(“Today’s Date is %s”,lr_eval_string(“{DDMMYY}”));

lr_save_datetime(“%d/%m/%Y”, DATE_NOW, “DDMMYYYY”);
lr_output_message(“Today’s Date is %s”,lr_eval_string(“{DDMMYYYY}”));

lr_save_datetime(“%B %d %Y”, DATE_NOW, “Today”);
lr_output_message(“Today is %s”,lr_eval_string(“{Today}”));

lr_save_datetime(“%B %d %Y”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%A”, DATE_NOW – ONE_DAY, “Yesterday”);
lr_output_message(“Yesterday was %s”,lr_eval_string(“{Yesterday}”));

lr_save_datetime(“%A”, DATE_NOW, “Today”);
lr_output_message(“Today is %s”,lr_eval_string(“{Today}”));

lr_save_datetime(“%A”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%X”, TIME_NOW , “Time”);
lr_output_message(“The time is %s (in this locale’s date format)”,lr_eval_string(“{Time}”));

lr_save_datetime(“%X”, TIME_NOW + ONE_HOUR , “Time”);
lr_output_message(“In one hour it will be %s”,lr_eval_string(“{Time}”));

lr_save_datetime(“%A”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%j”, DATE_NOW, “Today”);
lr_output_message(“Today is day %s in the year”,lr_eval_string(“{Today}”));

lr_save_datetime(“%Z”, DATE_NOW, “TimeZone”);
lr_output_message(“This machine is in the ‘%s’ time zone”,lr_eval_string(“{TimeZone}”));

lr_save_datetime(“%p”, DATE_NOW, “AMPM”);
if (strcmp (lr_eval_string(“{AMPM}”),”PM”)!=0)
{
lr_output_message(“Good Morning”);
}
else
lr_output_message(“Good Afternoon”);