LoadRunner中查找一个列表存到数组
[ 2006/10/10 19:22 | by ipaddr ]
LoadRunner中查找一个列表存到数组
LoadRunner可以通过函数web_reg_save_param查找一个网页的内容,指定左右边界,把中间的值取出来,供程序调用,但通常每次只取一个值,如果网页上有一个列表,需要将整个列表读入数组的话,可以在这个函数中带上ORD=All参数,告诉LR取出所有取值,返回在一个数组当中,用法如下:
web_reg_save_param("IPADDR",
"LB=XXXX",
"RB=YYYY",
"NotFound=warning",
"Search=Body",
"ORD=All",
LAST);
LR将在IPADDR_count里存放数组长度,每个元素可以IPADDR_n的格式来引用,下面举例说明.
//函数,传入tProductId为要查找的ID值,tIDArray为输出的数组,tArrayLength为该数组长度.
searchProductRelease(int tProductId,int * tIdArray,int tArrayLength)
{
char strProductId[20];
char strTmp[50],strTmp2[50];
int tALen=0;
int tmpi=0;
//将传入的C变量tProductId转换为LR变量strProductId
itoa(tProductId,strProductId,10);
lr_save_string(strProductId,"strProductId");
lr_start_transaction("searchProductRelease");
//查找与ProductID有关的列表,并将结果放在LR的数组tIDArray当中
web_reg_save_param("tIdArray",
"LB=XXXXXX",
"RB=YYYYYY",
"NotFound=warning",
"Search=Body",
"ORD=All",
LAST);
//以下语句为LR录制.
web_url("IPADDR",
"URL=http://elizabeth/maintain/product/productVersion.do?method=doShowList&productId={strProductId}&isPopUp=false",
"TargetFrame=_self",
"Resource=0",
"RecContentType=text/html",
"Referer=http://elizabeth/maintain/product/product.do?method=doShowInfo&productId={strProductId}&beforeMethod=null",
"Snapshot=t61.inf",
"Mode=HTML",
EXTRARES,
LAST);
lr_end_transaction("searchProductRelease", LR_AUTO);
strcpy(strTmp,lr_eval_string("{tIdArray_count}"));
tALen=atoi(strTmp);
if (tALen>tArrayLength)
{
tALen=tArrayLength;
}
for (tmpi=0;tmpi<tALen;tmpi++)
{
sprintf(strTmp2,"{tIdArray_%d}",tmpi+1);
strcpy(strTmp,lr_eval_string(strTmp2));
tIdArray[tmpi]=atoi(strTmp);
}
while (tmpi<tArrayLength)
{
tIdArray[tmpi]=0;
tmpi++;
}
return tALen;
}
可以如下调用
int productReleaseNum;
int releaseArray[20];
productReleaseNum=searchProductRelease(productId,releaseArray,20);
productReleaseNum里面存储ID数量.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
LoadRunner可以通过函数web_reg_save_param查找一个网页的内容,指定左右边界,把中间的值取出来,供程序调用,但通常每次只取一个值,如果网页上有一个列表,需要将整个列表读入数组的话,可以在这个函数中带上ORD=All参数,告诉LR取出所有取值,返回在一个数组当中,用法如下:
web_reg_save_param("IPADDR",
"LB=XXXX",
"RB=YYYY",
"NotFound=warning",
"Search=Body",
"ORD=All",
LAST);
LR将在IPADDR_count里存放数组长度,每个元素可以IPADDR_n的格式来引用,下面举例说明.
//函数,传入tProductId为要查找的ID值,tIDArray为输出的数组,tArrayLength为该数组长度.
searchProductRelease(int tProductId,int * tIdArray,int tArrayLength)
{
char strProductId[20];
char strTmp[50],strTmp2[50];
int tALen=0;
int tmpi=0;
//将传入的C变量tProductId转换为LR变量strProductId
itoa(tProductId,strProductId,10);
lr_save_string(strProductId,"strProductId");
lr_start_transaction("searchProductRelease");
//查找与ProductID有关的列表,并将结果放在LR的数组tIDArray当中
web_reg_save_param("tIdArray",
"LB=XXXXXX",
"RB=YYYYYY",
"NotFound=warning",
"Search=Body",
"ORD=All",
LAST);
//以下语句为LR录制.
web_url("IPADDR",
"URL=http://elizabeth/maintain/product/productVersion.do?method=doShowList&productId={strProductId}&isPopUp=false",
"TargetFrame=_self",
"Resource=0",
"RecContentType=text/html",
"Referer=http://elizabeth/maintain/product/product.do?method=doShowInfo&productId={strProductId}&beforeMethod=null",
"Snapshot=t61.inf",
"Mode=HTML",
EXTRARES,
LAST);
lr_end_transaction("searchProductRelease", LR_AUTO);
strcpy(strTmp,lr_eval_string("{tIdArray_count}"));
tALen=atoi(strTmp);
if (tALen>tArrayLength)
{
tALen=tArrayLength;
}
for (tmpi=0;tmpi<tALen;tmpi++)
{
sprintf(strTmp2,"{tIdArray_%d}",tmpi+1);
strcpy(strTmp,lr_eval_string(strTmp2));
tIdArray[tmpi]=atoi(strTmp);
}
while (tmpi<tArrayLength)
{
tIdArray[tmpi]=0;
tmpi++;
}
return tALen;
}
可以如下调用
int productReleaseNum;
int releaseArray[20];
productReleaseNum=searchProductRelease(productId,releaseArray,20);
productReleaseNum里面存储ID数量.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>