In performance testing, it is really important to simulate a realistic user path through an application. For example, randomly select an image link from a gallery or select a share from a share list. In such situations, you can use the LoadRunner lr_paramarr_random function to select a random value from a captured parameter array. Similarly, you can also write a code to do the same.
Before you use the above function, you will need to use web_reg_save_param function to capture all the ordinal values. This can be achieved by passing "ORD=ALL" into the function.
The following code demonstrates the use of lr_paramarr_random function. The code saves link Ids using web_reg_save_param function and then uses lr_paramarr_random function to randomly select an Id value. The value is passed as a parameter in web_text_link function to navigate to the appropriate webpage.
Before you use the above function, you will need to use web_reg_save_param function to capture all the ordinal values. This can be achieved by passing "ORD=ALL" into the function.
The following code demonstrates the use of lr_paramarr_random function. The code saves link Ids using web_reg_save_param function and then uses lr_paramarr_random function to randomly select an Id value. The value is passed as a parameter in web_text_link function to navigate to the appropriate webpage.
Action() { //Capture all the Link IDs web_reg_save_param("LinkID","LB=id=\"","RB=\" href=\"default.aspx?content=business_","ORD=ALL",LAST); lr_start_transaction("VU01_01_Homepage"); web_browser("website", DESCRIPTION, ACTION, "Navigate={WebsiteUrl}", LAST); lr_end_transaction("VU01_01_Homepage",LR_AUTO); lr_think_time(10); //Save a randomly selected ID to a Parameter lr_save_string(lr_paramarr_random("LinkID"),"RandomLink"); //Printout the randomly selected parameter lr_output_message("%s",lr_eval_string("{RandomLink}")); //Navigate to the appropriate webpage associated to the ID lr_start_transaction("VU01_02_RandomLink"); web_text_link("Links", "Snapshot=t2.inf", DESCRIPTION, "Id={RandomLink}", ACTION, "UserAction=Click", LAST); lr_end_transaction("VU01_02_RandomLink",LR_AUTO); web_browser("Sync", "Snapshot=t3.inf", DESCRIPTION, ACTION, "Sync", LAST); return 0; }Following is a screenshot of replay log, displaying the random id's selected for each iteration. It also displays the values captured using web_reg_save_param function.
No comments:
Post a Comment