Select last value from correction parameter list in LoadRunner

Problem:

How to select the last value from the correction parameter list in LoadRunner?

Explanation:

There are some practical scenarios in which the last dynamic value needs to be selected and passed in the next request. Here are some examples:

  1. A random number of values populate in a drop-down and the last value needs to be selected.  
  2. A random number of records appear on a page and the last record needs to be picked.

Solution:

To simulate these scenarios, firstly, you need to capture all the dynamic values using “Ord=All” in the correlation function.

web_reg_save_param("c_correlateParam",
                   "LB=value=\"",
                   "RB=\"",
                   "Ord=All",
                   LAST);

For your knowledge when you choose “Ord=All” then the correction parameter acts like an array. If you want to choose any specific value then you can append “_<number>” in the correlation parameter name. For example, if you need to pick a 2nd value then the correlation parameter will be “c_correlateParam_2”.

Now, there are 2 approaches to selecting the last value from the correction parameter list:

Approach 1:

In the first approach, you need to define two variables at the start and then use lr_paramarr_len and lr_paramarr_idx functions to save it in a C variable. The code is:

int arrLen;
char * lastVal;

web_reg_save_param("c_correlateParam",
                   "LB=value=\"",
                   "RB=\"",
                   "Ord=All",
                   LAST);

web_submit_form("abc",
.
.
.
.
.
.
    LAST );

arrLen = lr_paramarr_len("c_correlateParam");
lastVal = lr_paramarr_idx("c_correlateParam", arrLen);

where:

lr_paramarr_len: This function returns the length of an array which is equal to the number of values stored in that array. The returned value is stored in the arrLen variable in the above code.

lr_paramarr_idx: This function returns the value available at the specified place in the parameter array.

lr_paramarr_len() returns the length of the array means the location of the last value. This location is passed in lr_paramarr_idx() which fetches and returns the last value of the array. Like this, the last value of the correlation parameter is stored in the ‘lastVal’ variable and can be used further in the script.

Approach 2:

In the second approach, two variables need to be defined at the start:

int arrLen;
char lastVal[30];

web_reg_save_param("c_correlateParam",
                   "LB=value=\"",
                   "RB=\"",
                   "Ord=All",
                   LAST);

web_submit_form("abc",
.
.
.
.
.
.
    LAST );

sprintf (lastVal, "{c_correlateParam_%s}", lr_eval_string("{c_correlateParam_count}"));

lr_save_string( lr_eval_string(lastVal) ,"lastValue");

where:

lr_eval_string: This function evaluated the value of _count which is a count of dynamic values captured through the correlation function. It is as same as the length of the array.

sprintf: This is a C function which evaluates an LR variable and saves the (last) value into a C variable (named lastVal).

lr_save_string: The output of lr_eval_string() which evaluates the value of lastVal, is saved in an LR variable (named lastValue). Since this is an LR variable so can be used in the script using {“”}.

The difference between both approaches is

The first method returns the value in a C variable whereas the second method returns the value in the LR variable. You can get the value in the C variable using the second method as well. To know the difference between C (language-specific) and LR variable type, refer to this post.

You may be interested:


4 thoughts on “Select last value from correction parameter list in LoadRunner”

  1. Am using ord=all ,But am getting 99 values, I want to utilise only 13-39 values ….i want to write code?? can u help me…or is there any possibility other than writing code??

    Reply
    • Hi Sai,

      Generate the random value between 13 to 39 using ‘rand’ function of LoadRunner.

      int randNum;
      char * dynamicValue;
      web_reg_save_param(“c_correlatedValue”,…….., ORD = ALL)
      .
      .
      .
      randNum = rand()%27+13 //Generate the value between 13 to 39.
      dynamicValue = lr_paramarr_idx(“c_correlatedValue”, randNum);

      The dynamicValue parameter will have the correlation value available between 13th to 39th place.

      Reply
  2. Actually in my application after click on search some number records is gettting as response. These number of records is sending in web_custom_request as request body in coming request and click on submit.

    1 record means one customer
    for 1customer = 6different dynamic data is going like client Id, loanId, loan amount………….etc
    that means if get 100 records while click on search
    100*6 = 600 dynamic data

    if get 500 or 1000 records after click on search how can I handle……

    100 records are fixed it will be while replaying…..

    Reply
    • Hi Raju,

      As far as I understood the scenario, on clicking the search button, X number of records are coming in the response. X is dynamic and associated with a customer. Now you need to send back the customer information (which is in the record) in the next request, Now

      There are some queries to understand the scenario:
      1. Do you need to send all the records which came in the previous response simultaneously?
      2. Or do you need to send them one by one?

      Reply

Leave a Comment