首页 > 代码库 > LoadRunner例子:检查点为参数的一个例子
LoadRunner例子:检查点为参数的一个例子
LoadRunner例子:检查点为参数的一个例子
检查点是LoadRunner的一个功能,用来验证业务功能的正确性。如果检查的内容是变化的,脚本该如何写呢?
问题提出:LoadRunner订票网站例子中,创建一个虚拟用户脚本,在登陆完成之后,设立一个检查点,来检查“welcome, xxx”。其中xxx为登陆的用户名称。
解决方法:
1)使用web_find() 做检查点
Action()
{
//连接字符串,把welcome和用户名组合成一个字符串
char teststring[1024]="Welcome, ";
strcat( teststring,lr_eval_string("{username}") );
lr_output_message("%s", teststring);
lr_save_string( teststring,"findtext" );
// [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf]
//Parameter {WCSParam_Diff1} created by Correlation Studio
//关联操作
web_reg_save_param("WCSParam_Diff1",
"LB=userSession value="http://www.mamicode.com/,
"RB=>",
"Ord=1",
"RelFrameId=1.2.1",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(11);
lr_start_transaction("test");
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value=http://www.mamicode.com/{WCSParam_Diff1}", ENDITEM,
"Name=username", "Value=http://www.mamicode.com/{username}", ENDITEM, //参数化用户名
"Name=password", "Value=http://www.mamicode.com/bean", ENDITEM,
"Name=JSFormSubmit", "Value=http://www.mamicode.com/off", ENDITEM,
"Name=login.x", "Value=http://www.mamicode.com/42", ENDITEM,
"Name=login.y", "Value=http://www.mamicode.com/13", ENDITEM,
LAST);
//检查点
web_find("web_find",
"What={findtext}",
LAST);
lr_end_transaction("test", LR_AUTO);
return 0;
}
2)使用web_reg_find()做检查点
Action()
{
//字符串操作,生成要检查的字符串变量
char teststring[1024]="Welcome, <b>";
strcat( teststring,
lr_eval_string("{username}") );
lr_output_message("%s", teststring);
lr_save_string( teststring,"findtext" );
//关联
// [WCSPARAM WCSParam_Diff1 43 97279.0909680032fAADHQDpctVzzzzHDAAccpHfQtf] Parameter {WCSParam_Diff1} created by Correlation Studio
web_reg_save_param("WCSParam_Diff1",
"LB=userSession value="http://www.mamicode.com/,
"RB=>",
"Ord=1",
"RelFrameId=1.2.1",
"Search=Body",
"IgnoreRedirections=Yes",
LAST);
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_think_time(11);
lr_start_transaction("test");
//检查点
web_reg_find("Text={findtext}",
"Search=Body",
LAST);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value=http://www.mamicode.com/{WCSParam_Diff1}", ENDITEM,
"Name=username", "Value=http://www.mamicode.com/{username}", ENDITEM, //参数化登陆名称
"Name=password", "Value=http://www.mamicode.com/bean", ENDITEM,
"Name=JSFormSubmit", "Value=http://www.mamicode.com/off", ENDITEM,
"Name=login.x", "Value=http://www.mamicode.com/42", ENDITEM,
"Name=login.y", "Value=http://www.mamicode.com/13", ENDITEM,
LAST);
lr_end_transaction("test", LR_AUTO);
return 0;
}
LoadRunner例子:检查点为参数的一个例子