webTour样例程序总结

上一篇 / 下一篇  2015-04-28 18:14:17 / 个人分类:LR

LoadRunner性能测试巧匠训练营》中的脚本判断不靠谱问题。

特别说明下目的是在测性能的过程中,来保证施压的请求指向是符合业务或操作流程的目的。

也是可以利用lr 做些 接口 或页面的自动化检查。

其中Action.c脚本如下

Action()
{



// insert step 手动添加关联函数
/* web_reg_save_param("usession",
"LB=name=userSession value=",
"RB=>",
LAST);
*/



// Tree视图中 HTTP VIEW下/WebTours/nav.pl?in=home的Response body下找到usersession.选中值右键 create correlation自动生成的关联,自动使用的是ex正则关联函数
// Correlation comment - Do not change!Original value='115803.681004455fQfzzfVpitVzzzzHDfHDQpQVVAf' Name ='usession'

web_reg_save_param_ex(
"ParamName=usession",
"LB=userSession value=",
"RB=>\n<table border",
SEARCH_FILTERS,
"Scope=Body",
"RequestUrl=*/nav.pl*",
LAST);



lr_start_transaction("open");

web_url("WebTours",
"URL=http://192.168.66.87:1080/WebTours/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
LAST);


lr_end_transaction("open",LR_AUTO);

lr_think_time(5);


web_reg_find("Text={username}",
"savecount=username_count",
LAST);

lr_rendezvous("1");

lr_start_transaction("login");

web_submit_data("login.pl",
"Action=http://192.168.66.87:1080/WebTours/login.pl",
"Method=POST",
"RecContentType=text/html",
"Referer=http://192.168.66.87:1080/WebTours/nav.pl?in=home",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession","Value={usession}",ENDITEM,
"Name=username","Value={username}",ENDITEM,
"Name=password","Value={pwd}",ENDITEM,
"Name=JSFormSubmit","Value=on",ENDITEM,
"Name=login.x","Value=37",ENDITEM,
"Name=login.y","Value=6",ENDITEM,
LAST);

lr_output_message("%s 登录成功",lr_eval_string("{username}"));


//通过设置检查点获取登录用户的次数来判断登录是否成功是有缺陷的,比如当用户名与密码不匹配的时候也是判断登录成功,返回值也是LR_PASS!
//我们可以故意将参数username中的某一行user数据改成不存在的用户,如改test3为teest3,并在Tools->General Options中设置浏览器回放,F10回放时会发现webtour页面有错误提示"Web Tours Error-Incorrect Password"
if(atoi(lr_eval_string("{username_count}"))!=0)
lr_end_transaction("login",LR_PASS);
else
lr_end_transaction("login",LR_FAIL);
return0;
}



那么如何靠谱的判断一个用户真正登录成功了?

1 登录后的页面后设置文本或图像检查点,分别正在对应的成功或失败页面中设置检查点?

web_reg_find

2 登录请求发送后,webtours去检查判断下一个页面是成功还是失败页面?还是webtours有无响应体中成功或错误状态信息或参数信息?

web_url_check 还是 web_get_int_property

通过firebug看到成功和失败对应的页面url :

成功页面http://192.168.66.87:1080/WebTours/login.pl?intro=true

Welcome, jojo, to the Web Tours reservation pages. Using the menu to the left, you can search for new flights to book, or review/edit the flights already booked. Don't forget to sign off when you're done!

错误页面http://192.168.66.87:1080/WebTours/error.pl?error=badPassword

Error Web Tours Error - Incorrect Password The username/password combination you've entered is invalid. Please double check your entry. If it still does not work, you might need to re-register with our site. Thank you for your patience.


TAG:

 

评分:0

我来说两句

Open Toolbar