LoadRunner关联(附普通关联和数组随机提取关联案例)
关联实质是下一个请求发送参数来自于上一个请求的响应值(首先问开发,然后利用lr或fiddler查找比对录制与回放的请求/响应的源文件):头文件cookie、session、自定义
- 自动关联:菜单User>Scan scripts for correlations
- 手工关联:问开发+查看日志+Fillder请求与响应的源文件
- 调试技巧
1利用lr自身log日志(接口少还可以)
2利用log函数(自己打印)
3利用result(信息有时候不全)
4利用fiddler
=====关联基本提取,例子===
Action()
{
web_reg_save_param("mysessiontest","LB=userSession value=","RB=>",LAST);
web_reg_save_param("mysessiontest","LB=userSession value=","RB=>","NotFound=WARNING",LAST);//此种方式代表找不到参数不报error,只报waring
web_url("WebTours",
"URL=http://127.0.0.1:1080/WebTours/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);
lr_log_message("mysession is %s",lr_eval_string("{mysessiontest}"));
web_reg_find("Text=Welcome,admin1",
LAST);
lr_think_time(26);
web_submit_data("login.pl",
"Action=http://127.0.0.1:1080/WebTours/login.pl",
"Method=POST",
"TargetFrame=body",
"RecContentType=text/html",
"Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=userSession", "Value={mysessiontest}", ENDITEM,
"Name=username", "Value=admin1", ENDITEM,
"Name=password", "Value=admin1", ENDITEM,
"Name=JSFormSubmit", "Value=off", ENDITEM,
"Name=login.x", "Value=55", ENDITEM,
"Name=login.y", "Value=4", ENDITEM,
LAST);
return 0;
}
===========关联数组提取随机值的例子===========
Action()
{
web_add_cookie("loginname=abc; DOMAIN=IP");
//Correlation comment: Automatic rules - Do not change! Original value='0B967FE5B54ED8528A0BED089BD5C0B0' Name ='PeopleSoftJSessionID1'
web_reg_save_param_ex(
"ParamName=PeopleSoftJSessionID1",
"LB/IC=jsessionid=",
"RB/IC=?",
SEARCH_FILTERS,
"Scope=Body",
"IgnoreRedirections=Yes",
"RequestUrl=*/index.jsp*",
LAST);
web_url("index.jsp",
"URL=http://IP:8080/goods/index.jsp",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"URL=menu/img/jia.png", "Referer=http://IP.183:8080/goods/CategoryServlet;jsessionid=0B967FE5B54ED8528A0BED089BD5C0B0?method=findAll", ENDITEM,
LAST);
lr_think_time(9);
web_url("会员登录",
"URL=http://IP:8080/goods/jsps/user/login.jsp",
"TargetFrame=_parent",
"Resource=0",
"RecContentType=text/html",
"Referer=http://IP:8080/goods/jsps/top.jsp;jsessionid={PeopleSoftJSessionID1}",
"Snapshot=t2.inf",
"Mode=HTML",
EXTRARES,
"URL=/goods/images/login_sprites_20110808.png", ENDITEM,
"URL=/goods/images/login2.jpg", ENDITEM,
LAST);
web_submit_data("UserServlet",
"Action=http://IP:8080/goods/UserServlet",
"Method=POST",
"RecContentType=text/html",
"Referer=http://IP:8080/goods/jsps/user/login.jsp",
"Snapshot=t3.inf",
"Mode=HTML",
ITEMDATA,
"Name=method", "Value=login", ENDITEM,
"Name=loginname", "Value=abc", ENDITEM,
"Name=loginpass", "Value=abc", ENDITEM,
"Name=x", "Value=35", ENDITEM,
"Name=y", "Value=14", ENDITEM,
EXTRARES,
"URL=menu/img/jian.png", "Referer=http://IP:8080/goods/CategoryServlet?method=findAll", ENDITEM,
LAST);
web_reg_save_param("booklist",
"LB=bid=",
"RB=\">",
"Ord=ALL",
LAST);
web_url("BookServlet",
"URL=http://IP:8080/goods/BookServlet?method=findByCategory&cid=5F79D0D246AD4216AC04E9C5FAB3199E",
"TargetFrame=body",
"Resource=0",
"RecContentType=text/html",
"Referer=http://IP:8080/goods/CategoryServlet?method=findAll",
"Snapshot=t4.inf",
"Mode=HTML",
EXTRARES,
"URL=images/paginating_bg.png", "Referer=http://IP:8080/goods/BookServlet?method=findByCategory&cid=5F79D0D246AD4216AC04E9C5FAB3199E", ENDITEM,
LAST);
lr_save_string(lr_paramarr_random("booklist"), "rbid");
lr_log_message("rbid is %s",lr_eval_string("{rbid}"));
web_url("随机获取一本书",
"URL=http://IP:8080/goods/BookServlet?method=load&bid={rbid}",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://IP:8080/goods/BookServlet?method=findByCategory&cid=5F79D0D246AD4216AC04E9C5FAB3199E",
"Snapshot=t5.inf",
"Mode=HTML",
EXTRARES,
"URL=images/all.png", "Referer=http://IP:8080/goods/BookServlet?method=load&bid={rbid}", ENDITEM,
LAST);
return 0;
}