|
lr中for循环写入数据 参数化脚本
else 2010-07-08 18:20:25 阅读57 评论0 字号:大中小 订阅
网上达人的如下,不过有错误,后面跟着我修改后的脚本^_^,
“ Lr_save_string()函数和Itoa()函数的使用
/*
目的:使用for循环添加多条有规律的数据,比如说:a1、a2、a3......a1000
方法:从上面看1-1000是一个有序序列,并且前面的a都是固定的,所以只需要用for循环将1-1000循环出来就可以了。
但是loadrunner使用的是C语言的语法,所以不能向在java中一样,将两个变量直接相加(+)(+:连字符)
所以这个时候就需要将首先将int变量转换成string,然后再用lr_save_string()函数将该变量用loadrunner可以识别的参数化方式保存起来,再应用到录制的脚本中就可以了
函数简介:
int itoa ( int value, char *str, int radix );
函数目的:将int类型转换成string
参数介绍:value: 要转换的int型的值
str: 目标字符串,即将转换成的string值保存到str中
radix:转换数字时所用的基数 10:十进制;2:二进制……
int lr_save_string (const char *param_value, const char *param_name);
函数目的:将param_value值保存到param_name变量中
参数介绍:param_value:要保存的值
param_name: 变量名称
问题:为什么要用itoa()和lr_save_string()两个函数相结合使用呢?
因为lr_save_string()中的两个参数都是char类型的指针,int类型的值必须经过转换才能在lr_save_string()函数中使用,所以此处就要将itoa()和lr_save_string()两个函数相结合使用。
*/
Action()
{
int i;
char str[100]; //定义一个数组用来保存int类型转换后的值
for(i=0;i<=9;i++){
itoa(i,str,10);
lr_save_string(str,"ID");
lr_output_message("==str:=%s==ID:=%s====",str,lr_eval_string("{ID}"));
}
/*
用lr_save_string()将数组保存到变量中以后就可以应用到Loadrunner录制的脚本中了
{ID}:是loardrunner识别参数的方式
web_url("login",
"URL=http://server0.im.sonoro.cn:18001/login?username=a{ID}&password=test&autoLogin=false&1211433835878&1211433835878",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://server0.im.sonoro.cn:18001/proxy.html?1211433821547",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);
*/
return 0;
}
”
我录制的一个范例脚本如下:
Action()
{
int i;
char str[100]; //定义一个数组用来保存int类型转换后的值
web_url("sms",
"URL=http://127.0.0.1:7001/sms",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
web_add_cookie("VERSION=ZHUJI; DOMAIN=127.0.0.1");
lr_think_time(11);
web_submit_form("com.dvnchina.fw.svt.BfMain",
"Snapshot=t2.inf",
ITEMDATA,
"Name=XT_LOGIN_AREAID", "Value=057502", ENDITEM,
"Name=XT_LOGIN_NETID", "Value=057502ck", ENDITEM,
"Name=XT_LOGIN_ID", "Value=szf", ENDITEM,
"Name=XT_LOGIN_PASSWORD", "Value=1", ENDITEM,
"Name=B3", "Value=登 入", ENDITEM,
EXTRARES,
"Url=../jsp/images/arrow.gif", "Referer=http://127.0.0.1:7001/sms/jsp/login/welcome.jsp", ENDITEM,
LAST);
web_url("submenu.jsp",
"URL=http://127.0.0.1:7001/sms/jsp/submenu.jsp?subMenuID=21",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:7001/sms/jsp/login/welcome.jsp",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);
web_url("com.dvnchina.fw.svt.BfMain_2",
"URL=http://127.0.0.1:7001/sms/servlet/com.dvnchina.fw.svt.BfMain?ctrlBeanName=com.dvnchina.sms.warehouse.ctrl.Jump2STBBaseCtrl",
"Resource=0",
"RecContentType=text/html",
"Referer=http://127.0.0.1:7001/sms/jsp/submenu.jsp?subMenuID=21",
"Snapshot=t4.inf",
"Mode=HTML",
EXTRARES,
"Url=../jsp/images/arrow.gif", "Referer=http://127.0.0.1:7001/sms/servlet/com.dvnchina.fw.svt.BfMain?ctrlBeanName=com.dvnchina.sms.warehouse.ctrl.Jump2STBBaseCtrl", ENDITEM,
LAST);
lr_think_time(7);
for(i=0;i<=9;i++){
itoa(i,str,10);
lr_output_message("==str:=%s==ID:=%s====",str,lr_eval_string("{ID}"));
lr_save_string(str,"ID");
web_submit_data("com.dvnchina.fw.svt.BfMain_3",
"Action=http://127.0.0.1:7001/sms/servlet/com.dvnchina.fw.svt.BfMain",
"Method=POST",
"RecContentType=text/html",
"Referer=http://127.0.0.1:7001/sms/servlet/com.dvnchina.fw.svt.BfMain?ctrlBeanName=com.dvnchina.sms.warehouse.ctrl.Jump2STBBaseCtrl",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=ctrlBeanName", "Value=com.dvnchina.sms.warehouse.ctrl.InitAddItemsCtrl", ENDITEM,
"Name=AUTOVIRTUALPAIR", "Value=FALSE", ENDITEM,
"Name=ICTYPE_H", "Value=", ENDITEM,
"Name=STBID", "Value=hh{ID}", ENDITEM,
"Name=ICID", "Value=", ENDITEM,
"Name=UnitAddress", "Value=", ENDITEM,
"Name=SENDCMD", "Value=ON", ENDITEM,
"Name=Location", "Value=057502ck", ENDITEM,
"Name=Performance", "Value=1", ENDITEM,
"Name=STBType", "Value=STB04", ENDITEM,
"Name=ICType", "Value=TF", ENDITEM,
"Name=STBProducer", "Value=", ENDITEM,
"Name=ICProducer", "Value=", ENDITEM,
"Name=STBProduceDate", "Value=2010-7-8", ENDITEM,
"Name=CardProduceDate", "Value=2010-7-8", ENDITEM,
"Name=STBPrice", "Value=", ENDITEM,
"Name=CardPrice", "Value=", ENDITEM,
"Name=STBGoodsNo", "Value=", ENDITEM,
"Name=ICGoodsNo", "Value=", ENDITEM,
"Name=STBProvider", "Value=", ENDITEM,
"Name=ICProvider", "Value=", ENDITEM,
"Name=STBInDate", "Value=2010-7-8", ENDITEM,
"Name=ICInDate", "Value=2010-7-8", ENDITEM,
"Name=STBRemark", "Value=", ENDITEM,
"Name=ICRemark", "Value=", ENDITEM,
EXTRARES,
"Url=../jsp/images/arrow.gif", ENDITEM,
LAST);
}
return 0;
} |
|