05使用jmeter里调试一个下单接口

1、
用charles抓包,下单并收银的包;
将请求数据复制下来:
{
"appType": "5",
"brandID": 4881,
"content": {
"payment": {
"paymentType": 1,
"payments": [{
"paymentItems": [{
"changeAmount": 0.0,
"creatorId": 88888904893,
"creatorName": "admin",
"faceAmount": 0.01,
"payModeId": -3,
"payModeName": "现金",
"payModelGroup": 2,
"paySource": 1,
"paymentUuid": "45a5e68786f642debff4a5d3471291f8",
"refundWay": 1,
"usefulAmount": 0.01,
"brandIdenty": 4881,
"clientCreateTime": 1490690503204,
"clientUpdateTime": 1490690503204,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "794c0aad809c46a09d37656da29b67ba",
"changed": true
}],
"actualAmount": 0.01,
"beforePrivilegeAmount": 0.01,
"creatorId": 88888904893,
"creatorName": "admin",
"exemptAmount": 0.0,
"isPaid": 1,
"paymentType": 1,
"receivableAmount": 0.01,
"relateUuid": "1015ee3d8ac34cb1b52457dddcc79413",
"updatorId": 88888904893,
"updatorName": "admin",
"brandIdenty": *****,
"clientCreateTime": 1490690503202,
"clientUpdateTime": 1490690503203,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "45a5e68786f642debff4a5d3471291f8",
"changed": true
}],
"relateUuid": "1015ee3d8ac34cb1b52457dddcc79413",
"tradePayForm": 1,
"updatorId": 88888904893,
"updatorName": "admin"
},
"trade": {
"tradeExtra": {
"creatorId": 88888904893,
"creatorName": "admin",
"deliveryPlatform": 1,
"openIdenty": "",
"tradeUuid": "1015ee3d8ac34cb1b52457dddcc79413",
"updatorId": 88888904893,
"updatorName": "admin",
"brandIdenty": 4881,
"clientCreateTime": 1490690503189,
"clientUpdateTime": 1490690503189,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "e594bad1946a4347b44c4a41f68ee0e0",
"changed": true
},
"tradeItemExtras": [],
"tradeItemProperties": [{
"amount": 0.0,
"creatorId": 88888904893,
"creatorName": "admin",
"price": 0.0,
"propertyName": "盘",
"propertyType": 4,
"propertyUuid": "aa686678914f4997a526e08c6f7b03ee",
"quantity": 1,
"tradeItemUuid": "314b59ca4e914353bfb21df6b7ff54aa",
"updatorId": 88888904893,
"updatorName": "admin",
"brandIdenty": 4881,
"clientCreateTime": 1490690503189,
"clientUpdateTime": 1490690503189,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "ec1169b7ff004070ba297b91f2b9f30a",
"changed": true
}],
"tradeItems": [{
"actualAmount": 0.01,
"amount": 0.01,
"creatorId": 88888904893,
"creatorName": "admin",
"enableWholePrivilege": 2,
"feedsAmount": 0,
"guestPrinted": 1,
"isChangePrice": 1,
"issueStatus": 2,
"price": 0.01,
"propertyAmount": 0.0,
"quantity": 1,
"saleType": 2,
"skuId": 7,
"skuName": "二肥盐煎肉菜",
"skuUuid": "b7099f75d3354f3a89d90c1f1ea5bc81",
"sort": 0,
"tradeUuid": "1015ee3d8ac34cb1b52457dddcc79413",
"type": 0,
"unitName": "份",
"updatorId": 88888904893,
"updatorName": "admin",
"brandIdenty": 4881,
"clientCreateTime": 1490690503188,
"clientUpdateTime": 1490690503188,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "314b59ca4e914353bfb21df6b7ff54aa",
"changed": true
}],
"businessType": 1,
"creatorId": 88888904893,
"creatorName": "admin",
"deliveryType": 1,
"domainType": 1,
"privilegeAmount": 0.00,
"saleAmount": 0.01,
"skuKindCount": 1,
"source": 10,
"sourceChild": 1,
"tradeAmount": 0.01,
"tradeAmountBefore": 0.01,
"tradeNo": "101170328163617789000999",
"tradePayForm": 1,
"tradePayStatus": 1,
"tradePeopleCount": 1,
"tradeStatus": 3,
"tradeTime": 1490690177788,
"tradeType": 1,
"updatorId": 88888904893,
"updatorName": "admin",
"brandIdenty": 4881,
"clientCreateTime": 1490690503205,
"clientUpdateTime": 1490690503205,
"deviceIdenty": "94:a1:a2:31:05:a7",
"shopIdenty": 810003333,
"statusFlag": 1,
"uuid": "1015ee3d8ac34cb1b52457dddcc79413",
"changed": true
}
},
"deviceID": "94:a1:a2:31:05:a7",
"opVersionUUID": "89815fe0104e44e5b0330902b9094e8c",
"shopID": 810003333,
"systemType": "android",
"versionCode": "2110070802",
"versionName": "7.8.2"
}


2、
将请求信息复制到http请求的 Body Data里;
3、
填写好服务器名称或IP、路径、方法、编码方式;
4、创建一个用户定义的变量,并把请求里固定不变的变量放在里面,如图按名称和值来存放;便于统一修改;
5、在接口里把用户自定义变量引用进来;按变量格式引用;
6、创建一个BeanShell PreProcessor,将接口请求里的时间戳和uuid抽到这里,生成随机值并赋值给变量;
long timestamp = System.currentTimeMillis(); 获取系统当前时间。
vars.put("timestamp",timestamp+"");将当前时间赋值给timestamp变量;接口请求里可以通过${timestamp}引用;注意vars.put(String,String)必须传入字符串,时间戳需要格式转化为字符串,所以写成:timestamp+"";

String paymentUuid = UUID.randomUUID().toString().replaceAll("-", ""); 随机生成UUID并赋值给paymentUuid;
vars.put("paymentUuid",paymentUuid);将当前时间赋值给paymentUuid变量;接口请求里可以通过${paymentUuid}引用;
7、在接口请求里,引用uuid;
8、
针对tradeNo ,为了便于区别接口测试产生的数据与非接口操作产生的数据,在tradeNo上做一个区分;所以用一个固定数字开头;用时间结束;如下图定义;
9、在接口请求内容里引用tradeNo,如图所示;
10、运行:可以看到操作成功提示;
11、问题1:运行时提示,数据验证失败;
查看请求,发现传的参数有空格,导致不能识别;修改参数即可;
12、
问题2:响应的数据有乱码;
查看http请求设置,未填写Content encoding;由于传入的请求里有中文字符,所以需要填写Content encoding:utf-8;





posted @ 2017-03-31 16:24  一块糖  阅读(928)  评论(0编辑  收藏  举报