本篇内容主要讲解“LoadRunner中多值关联的处理方式”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“LoadRunner中多值关联的处理方式”吧!
需求:通过关联取得的ParamName参数可能存在多个值,需要对每个ParamName参数值进行处理
脚本:可通过3种不同的实现方式,将每个参数值作为HTTP请求内容发出
web_reg_save_param("ParamName",
"LB/IC="id":"OutputParameter.",
"RB/IC=","",
"Ord=All",
"Search=Body",
"RelFrameId=1",
LAST);
...
Paramcount=atoi(lr_eval_string("{ParamName_count}")); //参数个数
i=1;
while (i<=Paramcount) {
sprintf(str,"{ParamName_%d}",i); //生成ParamName_i
//方法一:将变量转为参数,直接在请求中使用参数
lr_save_string(lr_eval_string(str),"Value"); //对每个参数进行处理
web_submit_data("FreeQueryServlet_24",
"Action=http://datasvr01:8081/freequery/FreeQueryServlet",
"Method=POST",
"RecContentType=text/html",
"Referer=http://datasvr01:8081/freequery/js/freequery/businessview/Preview.html",
"Snapshot=t27.inf",
"Mode=HTTP",
ITEMDATA,
"Name=className", "Value=ClientReportService", ENDITEM,
"Name=methodName", "Value=addNewParam", ENDITEM,
"Name=params", "Value=["{ClientID}","OutputParameter.{Value}",""]", ENDITEM,
LAST);
//方法二:通过strcpy、strcat方式组织字符串,通过变量发送请求
strcpy(s,"Value=["{ClientID}","OutputParameter.");
strcat(s,str);
strcat(s,"",""]");
web_submit_data("FreeQueryServlet_24",
"Action=http://datasvr01:8081/freequery/FreeQueryServlet",
"Method=POST",
"RecContentType=text/html",
"Referer=http://datasvr01:8081/freequery/js/freequery/businessview/Preview.html",
"Snapshot=t27.inf",
"Mode=HTTP",
ITEMDATA,
"Name=className", "Value=ClientReportService", ENDITEM,
"Name=methodName", "Value=addNewParam", ENDITEM,
"Name=params", s, ENDITEM,
LAST);
//方法三:通过sprintf格式化输出生成需要的字符串,通过变量发送请求
sprintf(s,"Value=["{ClientID}","OutputParameter.%s",""]",str);
web_submit_data("FreeQueryServlet_24",
"Action=http://datasvr01:8081/freequery/FreeQueryServlet",
"Method=POST",
"RecContentType=text/html",
"Referer=http://datasvr01:8081/freequery/js/freequery/businessview/Preview.html",
"Snapshot=t27.inf",
"Mode=HTTP",
ITEMDATA,
"Name=className", "Value=ClientReportService", ENDITEM,
"Name=methodName", "Value=addNewParam", ENDITEM,
"Name=params", s, ENDITEM,
LAST);
i++;
}
到此,相信大家对“LoadRunner中多值关联的处理方式”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!