最近把之前学习过的LoadRunner翻出来又重新学习了一下,过程中出现web_reg_find的SaveCount计数一直为0的现象。前期脚本如下:
Login()
{
web_reg_save_param("Session",
"LB=name=userSession value=",
"RB=>",
LAST);
web_reg_find("Text=Web Tours reservation pages",
"SaveCount=nameCount",
"Search=Body",
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_start_transaction("Login");
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={Session}", ENDITEM,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=111111", ENDITEM,
"Name=JSFormSubmit", "Value=on", ENDITEM,
"Name=login.x", "Value=62", ENDITEM,
"Name=login.y", "Value=10", ENDITEM,
LAST);
lr_end_transaction("Login",LR_AUTO);
lr_output_message("username count is %s",lr_eval_string("{nameCount}"));
return 0;
}
输出的结果总是显示“Login.c(45): username count is 0”,后来想起web_reg_find函数要放在请求发送前面,然后就修改了一下web_reg_find的位置:
Login()
{
web_reg_save_param("Session",
"LB=name=userSession value=",
"RB=>",
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_start_transaction("Login");
web_reg_find("Text=Web Tours reservation pages",
"SaveCount=nameCount",
"Search=Body",
LAST);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={Session}", ENDITEM,
"Name=username", "Value=test1", ENDITEM,
"Name=password", "Value=111111", ENDITEM,
"Name=JSFormSubmit", "Value=on", ENDITEM,
"Name=login.x", "Value=62", ENDITEM,
"Name=login.y", "Value=10", ENDITEM,
LAST);
lr_end_transaction("Login",LR_AUTO);
lr_output_message("username count is %s",lr_eval_string("{nameCount}"));
return 0;
}
再次执行,显示结果符合预期。特别再次记录下。按书中所说,web_reg_find一定要放在实际请求提交之前,中间不能隔着其他东西。