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("string_you_want_to_search");
});
pm.test("Your test name", function () {var jsonData = pm.response.json();pm.expect(jsonData.value).to.eql(100);
});
pm.test("Body is correct", function () {pm.response.to.have.body("response_body_string");
});
pm.test("Content-Type is present", function () {pm.response.to.have.header("Content-Type");
});
pm.test("Response time is less than 200ms", function () {pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Successful POST request", function () {pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
pm.test("Status code name has string", function () {pm.response.to.have.status("Created");
});
// ps: 1.在断言中不能够使用{{}}的方式取全局变量。
// 2.一般通过:pm.globals.get("times") 取全局变量的值
四、Postman处理加解密
//Base64位加密//把需要加密的值转换成utf-8的编码格式3
var us = CryptoJS.enc.Utf8.parse("admin");
var pw = CryptoJS.enc.Utf8.parse("123");//对转换后的值做Base64加密
var bs64_us = CryptoJS.enc.Base64.stringify(us);
var bs64_pw = CryptoJS.enc.Base64.stringify(pw);
//设置为全局变量
pm.globals.set("bs64_us", bs64_us.toString().toUpperCase());
pm.globals.set("bs64_pw", bs64_pw.toString().toUpperCase());//Base64位解密
var intermediate = CryptoJS.enc.Base64.parse(responseBody);
var base64Content = intermediate.toString(CryptoJS.enc.Utf8);
//对解密后的数据进⾏提取json部分
var jsonValue = base64Content.substring(base64Content.indexOf("{"), base64Content.lastIndexOf("}") + 1);
console.log(jsonValue);