lr_paramarr_idx function in loadrunner example

It is very important loadrunner function which is used in LoadRunner to find out parameter at certain position/ index from the list of parameter values.

It is used most commonly with the function web_reg_save_param which returns list of parameter values. Let us suppose that  the function web_reg_save_param returns 10 values and we have to find value at position/index five, then we need to use this function. Let us understand it with example given below. URL taken in this example is as given below.

http://newtours.demoaut.com/mercurysignon.php

After opening the URL given above, vivek we will get the following page shown in the screenshot given below.We can see that there are two text boxes on the given page. These two text boxes have similar HTML structure.

lr_paramarr_idx Function in Loadrunner Example1

We can clearly see that HTML structure of both the text boxes is as given below.

<input maxlength=60 name=“userName” size=“20”>

<input maxlength=60 name=“password” size=“20” type=password>

We can also see common pattern between two text boxes where left boundary HTML structure and wonderstruck right boundary HTML structure is same. We can see that left common structure is is as given below.

input maxlength=60 name=

We can see right boundary common structure between the two text boxes, which is given as below .

size=

We can see the same in the screenshot given below where clear picture of left boundary boundary and right boundary is displayed.

lr_paramarr_idx Function in Loadrunner Example2

But before executing any code, we have to remember one thing that we have to do particular setting in runtime setting window of LoadRunner. We have to enable Extended log and enable Parameter Substitution. It is very mandatory to do so otherwise we won’t be able to see the parameter results returned by function web_reg_save_param. Setting can be seen in the form of screenshot given below.

lr_paramarr_idx Function in Loadrunner Example3

We can see left boundary common structure As given below.This will be used in our function web_reg_save_param

lr_paramarr_idx Function in Loadrunner Example4

We can also see right boundary common HTML structure between these two text boxes which is visible on the page, which is given as below in the form of screenshot. We will use this right boundary in our function web_reg_save_param.

lr_paramarr_idx Function in Loadrunner Example5

Now let us see the code example given below to understand the function in a better way. We have used the function web_reg_save_param to return two values and we have used left boundary and right boundary of the HTML structure. We can also see that in the screenshot given above and we have also seen that value between left boundary and right boundary is    “username” and “password”.Let us see the example given below.

Action()

{

//Declaring one variable

                int arrSize;

//Using one Loadrunner function which returns  two values

web_reg_save_param(“pUserName1”, “LB=input maxlength=60 name=”, “RB=size=”,  “ORD=ALL”, LAST);              

                web_url(“mercurysignon.php”,

                                “URL=http://newtours.demoaut.com/mercurysignon.php”,

                                “Resource=0”,

                                “RecContentType=text/html”,

                                “Referer=”,

                                “Snapshot=t13.inf”,

                                “Mode=HTML”,

                                LAST);

arrSize = lr_paramarr_len(“pUserName1”);

//Printing the value of variable “arrSize” in the output log window of Loadrunner

lr_output_message(“Size of array: %d”, arrSize);

//Printing the first value of the parameter

lr_output_message(“%s”,lr_eval_string(lr_paramarr_idx(“pUserName1”,1)));

//Printing the second value of the parameter

lr_output_message(“%s”,lr_eval_string(lr_paramarr_idx(“pUserName1”,2)));

                return 0;

}

We can see how same code appears in LoadRunner window, in the form of a screenshot given below.

lr_paramarr_idx Function in Loadrunner Example6

After doing all the necessary run time setting and executing the code, we get the following output. We can see both the values between left boundary and right boundary , in the output log given below

Starting action Action.

Action.c(6): web_reg_save_param started            [MsgId: MMSG-26355]

Action.c(6): Registering web_reg_save_param was successful      [MsgId: MMSG-26390]

Action.c(9): web_url(“mercurysignon.php”) started          [MsgId: MMSG-26355]

Action.c(9): Notify: Saving Parameter “pUserName1_1 = “userName” “.

Action.c(9): Notify: Saving Parameter “pUserName1_2 = “password” “.

Action.c(9): Notify: Saving Parameter “pUserName1_count = 2”.

Action.c(9): web_url(“mercurysignon.php”) highest severity level was “warning”, 27657 body bytes, 2289 header bytes, 13 chunking overhead bytes          [MsgId: MMSG-26387]

Action.c(18): Notify: Parameter Substitution: parameter “pUserName1_count” =  “2”

Action.c(20): Size of array is: 2

Action.c(22): Notify: Parameter Substitution: parameter “pUserName1_1” =  “”userName” “

Action.c(22): “userName”

Action.c(24): Notify: Parameter Substitution: parameter “pUserName1_2” =  “”password” “

Action.c(24): “password”

Ending action Action.

We can see both the values between left boundary and right boundary defined in the function web_reg_save_param in the form of a screenshot given below. We can see the parameter values at position 1 and position 2 in the log given below. Both the values have been highlighted in the screenshot.

lr_paramarr_idx Function in Loadrunner Example7

Overall, we can say that it is very useful function to find out parameter values at certain index from the list of parameter values.

For more articles like these see our Loadrunner tutorial

Leave a Comment