一、结合Fiddler2抓包
1、在Action()脚本中添加
web_set_proxy("127.0.0.1:8888");
2、Fiddler设置如下
fiddler的Filters需要添加如下设置 "Show only if URL contains"表示URL中包含某字段的URL
3、执行脚本,查看请求报文和响应报文
二、关联
1、什么是关联
关联(correlation):脚本回放过程中,客户端发出请求,通过关联函数所定义的左右边界值(也就是关联规则),在服务器所响应的内容中查找,得到相应的值,已变量的形式替换录制时的静态值,从而向服务器发出正确的请求,这种动态获得服务器响应内容的方法被称作关联。也是把脚本中某些写死的数据,转变成动态的数据。
什么内容需要关联:当脚本中的数据每次回放都发生变化时,并且这个动态数据在后面的请求中需要发送给服务器,那么这个内容需要通过关联来询问服务器,获得该数据的变化结果
2、web_reg_save_param函数说明
语法:
int web_reg_save_param(const char *ParamName, <list of Attributes>, LAST);
参数说明:
· ParamName: 存放得到的动态内容的参数名称
· list of Attributes: 其它属性,包括:Notfound, LB, RB, RelFrameID, Search, ORD, SaveOffset, Convert, SaveLen。属性值不分大小写
o Notfound: 当在返回信息中找不到要找的内容时应该怎么处理
o Notfound=error: 当在返回信息中找不到要找的内容时,发出一个错误讯息。这是缺省值。
o Notfound=warning: 当在返回信息中找不到要找的内容时,只发出警告,脚本也会继续执行下去不会中断。
o LB( Left Boundary ) : 返回信息的左边界字串。该属性必须有,并且区分大小写。
o RB( Right Boundary ): 返回信息的右边界字串。该属性必须有,并且区分大小写。
o RelFrameID: 相对于URL而言,欲查找的网页的Frame。此属性质可以是All或是数字,该属性可有可无。
o Search : 返回信息的查找范围。可以是Headers,Body,Noresource,All(缺省)。该属性质可有可无。
o ORD : 说明第几次出现的左边界子串的匹配项才是需要的内容。该属性可有可无,缺省值是1。如为All,则将所有找到的内容储存起来。
o SaveOffset : 当找到匹配项后,从第几个字元开始存储到参数中。该属性不能为负数,缺省值为0。
o SaveLen :当找到匹配项后,偏移量之后的几个字元存储到参数中。缺省值是-1,表示一直到结尾的整个字串都存入参数。
3、示例
- 要搜索哪个报文,就把web_reg_save_param写在它所在的事务中
- 获取的参数不能包含双引号,否则会报错,如下图中itemName的获取,如果获取整串data就会报错,所以只能单个参数获取
lr_start_transaction("回车");
//从loadPickDetail.actio请求的报文主体中搜索对应的参数
web_reg_save_param("req","LB=","RB=", LAST);
web_reg_save_param("itemCode","LB=itemCode\":\"","RB=\"", LAST);
web_reg_save_param("itemName","LB=itemName\":\"","RB=\"", LAST);
web_reg_save_param("customerName","LB=customerName\":\"","RB=\"", LAST);
web_reg_save_param("itemProduceDate","LB=itemProduceDate\":\"","RB=\"", LAST);
web_reg_save_param("locationContainerId","LB=locationContainerId\":\"","RB=\"", LAST);
web_reg_save_param("locationId","LB=locationId\":\"","RB=\"", LAST);
web_reg_save_param("locationName","LB=locationName\":\"","RB=\"", LAST);
web_reg_save_param("storageDate","LB=storageDate\":\"","RB=\"", LAST);
web_submit_data("loadPickDetail.action",
"Action=http://10.16.8.81/BH_CLIS/PickList/loadPickDetail.action",
"Method=POST",
"RecContentType=application/json",
"Referer=http://10.16.8.81/BH_CLIS/PickList/toPickRecover.action?functionId=933000",
"Snapshot=t33.inf",
"Mode=HTML",
ITEMDATA,
"Name=pickListId", "Value={jianhuohuidan}", ENDITEM,
LAST);
lr_output_message("The req for search is: %s",lr_eval_string("{req}"));
lr_output_message("The data for search is: %s",lr_eval_string("{data}"));
lr_end_transaction("回车",LR_AUTO);
lr_start_transaction("提交");
web_submit_data("pickCompleteV2.action",
"Action=http://10.16.8.81/BH_CLIS/PickList/pickCompleteV2.action",
"Method=POST",
"RecContentType=application/json",
"Referer=http://10.16.8.81/BH_CLIS/PickList/toPickRecover.action?functionId=933000",
"Snapshot=t34.inf",
"Mode=HTML",
ITEMDATA,
"Name=pickListId", "Value={jianhuohuidan}", ENDITEM,
"Name=pdl", "Value=[{\"accountId\":\"\",\"actualAmount\":0,\"actualOddQuantity\":\"\",\"actualPeiceNum\":\"\",\"actualPickQty\":1,\"barcodeNumber\":\"\",\"bigItemGroupId\":\"\",\"bigItemGroupName\":\"\",\"boxMinPackageRate\":\"\",\"boxNo\":\"\",\"businessLockFlag\":\"\",\"businessType\":\"\",\"carrierCode\":\"\",\"carrierId\":\"\",\"carrierName\":\"\",\"checkQuantity\":0,\"checkStatus\":12020,\"containerCode\":\"\",\"containerId\":\"\",\"createdBy\":\"\",\"creationMethod\":\"\",\"creationTime\""
":null,\"customerCode\":\"\",\"customerId\":\"\",\"customerName\":\"{customerName}\",\"deleteFlag\":\"\",\"diffDesc\":\"\",\"diffPickQty\":0,\"diffReasonId\":\"\",\"entityId\":null,\"groupFlag\":\"\",\"id\":\"\",\"isAssignSequence\":0,\"itemCode\":\"{itemCode}\",\"itemCube\":0,\"itemGroupCode\":\"\",\"itemGroupId\":\"\",\"itemGroupName\":\"\",\"itemId\":\"\",\"itemName\":\"{itemName}\",\"itemPackagingId\":\"\",\"itemPackagingName\":\"\",\"itemProduceDate\":\"{itemProduceDate}\",\""
"locationContainerId\":\"{locationContainerId}\",\"locationId\":\"{locationId}\",\"locationName\":\"{locationName}\",\"lotNumber\":\"\",\"mergeLocationId\":\"\",\"mergeLocationName\":\"\",\"normalFlag\":\"\",\"oddQuantity\":\"\",\"orderDetailId\":\"\",\"orderFrom\":\"\",\"orderId\":\"\",\"orderRoute\":\"\",\"peiceNum\":\"\",\"pickListDetailStatus\":\"\",\"pickListId\":\"\",\"pickMode\":\"\",\"pickSequence\":\"\",\"pickZoneId\":\"\",\"pickZonePopno\":\"\",\"ptlLocationId\":"
"\"\",\"receiverCode\":\"\",\"receiverId\":\"\",\"receiverName\":\"\",\"relationedCustomerCode\":\"\",\"relationedCustomerId\":\"\",\"relationedCustomerName\":\"\",\"routeOrder\":\"\",\"sequenceId\":\"\",\"shouldPickQty\":1,\"singleFlag\":\"\",\"singleQuantity\":0,\"splitGoodsStatus\":\"\",\"storageDate\":\"{storageDate}\",\"units\":\"\",\"updateMethod\":\"\",\"updateTime\":null,\"updatedBy\":\"\",\"warehouseAreaId\":\"\",\"warehouseCode\":\"\",\"warehouseId\":\"\",\"warehouseName\":\"\",\""
"wholeOrSpare\":\"\",\"zoneName\":\"\"}]", ENDITEM,
LAST);
lr_end_transaction("提交",LR_AUTO);
配置log日志显示,lr_output_message函数才能发挥作用
四、压测配置