使用LR注册1个PHPWind网站会员
分析:
请求网站首页的时候,服务器会返回一个token(令牌)给客户端(LoadRunner),该token的值是动态的,注册会员需要使用该令牌,如果令牌不符的话,则不允许注册。可以使用关联技术将该token的内容保存到变量里面,变量名自定义(比如:token),然后使用该变量提交注册请求。
设计LR脚本
注册一个会员的脚本如下:
Action()
{
web_reg_save_param("token",
"LB=name=\"csrf_token\" value=\"",
"RB=\"/>",
"Ord=1",
LAST);
web_url("index.php",
"URL=http://192.168.0.153:8090/phpwind/index.php",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t19.inf",
"Mode=HTML",
EXTRARES,
"Url=themes/site/default/images/main_bg.png", ENDITEM,
"Url=themes/site/default/images/common/style_icon.png", ENDITEM,
"Url=themes/site/default/images/common/core_bg.png", ENDITEM,
"Url=themes/site/default/images/tips/gray_big.png", ENDITEM,
"Url=http://www.bing.com/favicon.ico", "Referer=", ENDITEM,
"Url=../favicon.ico", "Referer=", ENDITEM,
"Url=res/js/dev/pages/common/global.js?v=20161021", ENDITEM,
"Url=res/js/dev/jquery.js?v=20161021", ENDITEM,
"Url=res/js/dev/pages/bbs/postGuide.js?v=20161021", ENDITEM,
LAST);
web_url("index.php_2",
"URL=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register",
"Resource=0",
"RecContentType=text/html",
"Referer=http://192.168.0.153:8090/phpwind/index.php",
"Snapshot=t21.inf",
"Mode=HTML",
EXTRARES,
"Url=res/js/dev/util_libs/validate.js?v=20161021", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM,
"Url=res/js/dev/util_libs/emailAutoMatch.js?v=20161021", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM,
"Url=themes/site/default/images/register/arrow_reg.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM,
"Url=themes/site/default/images/tips/small.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register", ENDITEM,
LAST);
web_submit_data("index.php_12",
"Action=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=dorun",
"Method=POST",
"RecContentType=text/html",
"Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register",
"Snapshot=t31.inf",
"Mode=HTML",
ITEMDATA,
"Name=username", "Value=jojo2", ENDITEM,
"Name=password", "Value=123456", ENDITEM,
"Name=repassword", "Value=123456", ENDITEM,
"Name=email", "[email protected]", ENDITEM,
"Name=csrf_token", "Value={token}", ENDITEM,
EXTRARES,
"Url=themes/site/default/images/common/style_bg.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM,
"Url=themes/site/default/images/common/loading.gif", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM,
"Url=themes/site/default/images/common/header_dorp.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM,
"Url=themes/site/default/images/common/core_icon.png", "Referer=http://192.168.0.153:8090/phpwind/index.php?m=u&c=register&a=guide", ENDITEM,
LAST);
return 0;
}
回放脚本
服务器返回注册成功的页面