Back to Blog

Vugen: Using LAST Value For web_reg_save_param_ex

Whenever the ORD=ALL attribute is used with the web_reg_save_param_ex function, VuGen creates an array containing the number of instances that are actually captured. It also stores the total count for the number of instances automatically. This count can be referenced by getting the value of “_count”. For example, if the parameter name is ParamName, a separate parameter ParamName_count will be available with number of times the value was captured. This can also serve as index for last values captured. Use the sample code below to reference and use the last value captured by LoadRunner. You can get creative and use a random value instead or walk through the array to get other values too.

Example:

Action()
 {
 int i;
 char last[30];

//Capture all occurrences of strings between <td> and </td>
 web_reg_save_param_ex("MyParam",
 "LB=<td>",
 "RB=</td>",
 "Ord=ALL",
 LAST);

web_url("coolwebsite",
 "URL=http://www.youstupidmonkey#%$.com/",
 "Resource=0",
 "RecContentType=text/html",
 "Referer=",
 "Mode=HTTP",
 LAST);

//Get the total count of the parameter and
//save the information to a string

 sprintf (last, "{MyParam_%s}", lr_eval_string("{MyParam_count}"));

//extract the value of the last item and
// save it to a parameter called pLastValue

 lr_save_string( lr_eval_string(last) ,"pLastValue");

//send a message to the log showing the value of pLastValue

 lr_message("last value is %s", lr_eval_string("{pLastValue}"));

return 0;
 }
Back to Blog