ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=35", ENDITEM,
"Name=login.y", "Value=14", ENDITEM,
LAST);
// Check result
if (atoi(lr_eval_string("{Welcome_Count}")) > 0){ //判断如果Welcome字符串出现次数大于0
lr_output_message("Log on successful."); }//在日志中输出Log on successful
else{ //如果出现次数小于等于
lr_error_message("Log on failed"); //在日志中输出Log on failed
return(0); }
我觉得这个方法非常有用,我们可以举一反三,应用到我们实际的项目
注:在录制过程中添加的检查点,用到的函数是web_reg_find(),且参数只有“Text=”
3、web_image_check()函数参数说明:
web_image_check("web_image_check","Alt=","Src=",LAST);
参数解释:“Alt”和“Src”的值直接取该图片在网页源代码中相应参数的值;
注意事项:使用该函数时,要在Vuser->Run-Tme Settings中勾选Enable Image and text check,具体操作请看web_find()中的注意事项。
经过测试,该函数用到查找内容前面或后面,都不影响查找结果。
举例说明(脚本)
该脚本记录的是登陆系统后退出的操作,在脚本中用到atoi()函数和lr_eval_string(”{SaveCount定义的变量}”)两个函数结合使用,判断查找内容出现的次数是否大于0,若大于0,则输入登录成功的信息。
vuser_init()
{
web_url("xjcost",
"URL=http://gczj-server8:9205/xjcost/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=jsp/images/index/index.swf", ENDITEM,
"Url=jsp/images/index/xxfb2.gif", ENDITEM,
"Url=jsp/images/index/ywpt2.gif", ENDITEM,
LAST);
web_url("userAction.struts",
"URL=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
LAST);
return 0;
}
Action()
{
lr_start_transaction("Log_on");
lr_rendezvous("Log_on");
web_add_cookie("userAccount=admin; DOMAIN=gczj-server8");
web_reg_find("Text=欢迎您",
"SaveCount=欢迎您_Count",
LAST);
web_image_check("web_image_check",
"Src=/xjcost/jsp/images/index1/edit_01.gif",
LAST);
web_submit_data("userLogin.struts",
"Action=http://gczj-server8:9205/xjcost/userLogin.struts?actionType=userLogin",
"Method=POST",
"RecContentType=text/html",
"Referer=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",
"Snapshot=t3.inf",
"Mode=HTML",
ITEMDATA,
"Name=userAccount", "Value=admin", ENDITEM,
"Name=pwd", "Value=1111", ENDITEM,
EXTRARES,
"Url=jsp/images/index1/edit_01a.gif", "Referer=http://gczj-server8:9205/xjcost/userLogin.struts?actionType=userLogin", ENDITEM,
LAST);
web_find("web_find",
"What=欢迎您",
LAST);
lr_end_transaction("Log_on",LR_AUTO);
//检查是否登录成功
//如果“欢迎您”这个字符出现次数大于0,输出“Log on successfully!”
if(atoi(lr_eval_string("{欢迎您_Count}"))>0)
lr_output_message("Log on successfully!");
else
lr_error_message("Log on failed!");
return 0;
return 0;
}
//atoi()函数的作用是将一个ASCII字符串转换为整型
//lr_eval_string()函数作用是取得参数值,将字符串变量中的参数值替换为当前的参数值并将这个字符串返回
vuser_end()
{
lr_think_time(4);
web_url("userAction.struts_2",
"URL=http://gczj-server8:9205/xjcost/userAction.struts?actionType=reLogin",
"Resource=0",
"RecContentType=text/html",
"Referer=",