pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("填入校验的字符串");
});
三、响应body等于字符串
pm.test("Body is correct", function () {
pm.response.to.have.body("输入期望接口返回的结果值");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(填入期望的时间,单位ms);
});
五、JSON结果值返回校验
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.字段).to.eql(期望字段值);
});
举例:响应主体{"code":"S","msg":"SUCCESS","data":[{"employeeCode":"100000001","employeeName":"王","time":"09:27:33"}]}
判断code是否为S pm.expect(jsonData.code).to.eql("S");
判断employeeName是否为王 pm.expect(jsonData.data[0].employeeName).to.eql("王");
六、接口A返回值,用在B接口
//解析json
var jsonData = pm.response.json();
//取值
var employeeCode=jsonData.data[0].employeeCode;
//调试,再view-show postman console中可查看
console.log(employeeCode);
//设置全局变量
pm.globals.set("gh", employeeCode);
//B接口可直接调用,l例如:http://xxx.xxx.com/getCode?employeeCode={{gh}}