(1)关联介绍
在脚本录制生成中,录制到一些服务器分配的数据。但是在回放脚本的过程中,服务器又重新分配好了新的数据,导致这些录制生成的数据已经无法使用,需要重新获取服务器的最新数据。
关联可以在脚本中捕获到服务器分配的数据,存储到参数中,需要使用的时候从参数中取出来,从而保重请求的数据是服务器最新分配的数据。
(2)手动关联
1、使用位置:使用在捕获的消息包对应请求之前。
web_reg_save_parm(“参数名称”,“定位的属性值列表”,LAST);
常用属性:
基本运用示例:
int iRetVal = LR_PASS;
lr_save_string( "HTTP%2F1%2E1%20301%20Moved%20Permanently%0A%0D"
"Content%2DType%3A%20text%2Fhtml%0A%0D"
"Date%3A%20Sun%2C%2014%20Feb%202010%2011%3A15%3A34%20GMT%0A%0D"
"%0A%0D"
"aaLLb%20bLLc%20%2E%2ecRRddRReeRRffLLggsadfsdfsdfRRhhRRiiLLj%20%2d%2DjRRkkLLmmLLnnRRoooRRpppLLqqq%0A%0D",
"inParam" );
iRetVal = web_reg_save_param_ex(
"ParamName=newParam",
"LB/IC=ll",
"RB/BIN/RE=RR",
"Ordinal=all",
"SaveLen=-1",
"DFEs=UrlEncoding",
SEARCH_FILTERS,
"Scope=body",
LAST);
lr_output_message("Return value = %d (%s).", iRetVal, iRetVal == LR_PASS ? "LR_PASS" : "LR_FAIL" );
web_submit_data("echo.asp_2",
"Action=http://localhost/cgi-bin/echo.asp",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://localhost/cgi_examples/echo_asp.html",
"Snapshot=t4.inf",
"Mode=HTML",
ITEMDATA,
"Name=code", "Value={inParam}", ENDITEM,
LAST);
正则表达式的运用示例:
lr_save_string( "LL111 Value1 111RR\r\n"
"LL222 Value2 222RR\r\n"
"LL333 Value3 333RR\r\n"
"LL444 Value4 444RR\r\n",
"inParam" );
web_reg_save_param_ex(
"paramName=ex_example0",
"LB/RE=LL111",
"RB/RE=222RR",
LAST);
web_reg_save_param_ex(
"paramName=ex_example1",
"LB/RE=LL[0-9]*", // "LL" followed by zero or more symbols in range [0-9]
"RB/RE=.RR", // Any symbol followed by "RR"
LAST);
web_reg_save_param_ex(
"paramName=ex_example2",
"LB/RE=LL[0-9]+", // "LL" followed by at least one symbol in range [0-9]
"RB/RE=.2RR", // Any symbol followed by "2RR"
LAST);
web_reg_save_param_ex(
"paramName=ex_example3",
"LB/RE=LL(33)+", // "LL" followed by at least one instance of string "33"
"RB/RE=[3a]RR", // Exactly one symbol ('3' or 'a') followed by "RR"
LAST);
web_reg_save_param_ex(
"paramName=ex_example4",
// "LL" or "123" folowed by at least one instance
// of string containing symbols [4-9] and space
"LB/RE=((LL)|(123))[4-9 ]+",
// At least one instance of string containing symbols [4-9]
// and space followed by "RR"
"RB/RE=[4-9 ]+RR",
LAST);
2、查看参数提交日志
(2)录制后关联
目的就是录制过程中的响应和回放过程中的数据做对比,然后做出评判是否需要关联(足够了解业务知识后,推荐手动关联)
(3)录制过程中关联