LoadRunner中多值关联的3种处理方式
需求:通过关联取得的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++; }
作者:Agoly 出处:https://www.cnblogs.com/qmfsun/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |