"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
// Set up check for successful login by looking for "Welcome"
web_reg_find("Text=Welcome",
"SaveCount=Welcome_Count",
LAST);
// Now log in
web_submit_form("login.pl",
"Snapshot=t2.inf",
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",