来至:gotesting软件测试联盟论坛 http://www.78test.com
原创vuser脚本片段:
lr_start_transaction("trans_login");
//设置检查的内容,在savecount变量里面记录查找到的次数
web_reg_find("Text=欢迎您","SaveCount=loginss_count",LAST);
//登录(登录录制的自动生成代码)
web_submit_data("loginAction.do;jsessionid=16D156A310B3804B354123F7CDEE5211",
"Action=http://****/loginAction.do;jsessionid={JSESSIONID2}",
"Method=POST",
............
LAST);
//检查登录是否成功
// if(strcmp(lr_eval_string("{loginss_count}"),"0")==0) 这两个if等效
if(atoi(lr_eval_string("{loginss_count}"))==0)
// lr_output_message("login failed登录失败!");
lr_error_message("login failed登录失败!username:%s,pwd:%s",lr_eval_string("{username}"),lr_eval_string("{pwd})"));//打印出错误信息,同时把登录错误时的用户名、密码打印出来。
else
lr_output_message("login successful登录成功!");
lr_end_transaction("trans_login", LR_AUTO);
网上摘录的web_reg_find用法:
web_reg_find
该函数的作用是“在缓存中查找相应的内容”,常用参数及含义如下:
web_reg_find("Search=Body", //定义查找范围
"SaveCount=ddd", //定义查找计数变量名称
"Text=aaaa", //定义查找内容
LAST);
使用该函数注意以下事项:
1、 位置
该函数写在要查找内容的请求之前,通常情况下写在如下六个函数之前:
Web_castom_request();web_image();web_link();web_submit_data();web_submit_form();web_url()
2、 使用技巧
在该函数的参数中有个“SaveCount”,该参数可以记录在缓存中查找内容出现的次数,我们可以使用该值,来判断要查找的内容是否被找到,下面举个例子来说明:(引用LR的帮助中的例子)
// Run the Web Tours sample
web_url("MercuryWebTours",
"URL=http://localhost/MercuryWebTours/",
"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",
..........
LAST);
// Check result
if (atoi(lr__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); }
http://blog.163.com/tech_qa/blog/static/1301763492009101724535999/ |