bbccaaa 2019-10-23
postman官方文档:https://learning.getpostman.com/docs/postman/scripts/test_examples/

// 检查响应主体是否包含字符串
pm.test("登录成功", function () {
pm.expect(pm.response.text()).to.include("登录成功");
});// 通过json值断言
pm.test("登录成功,code值等于0", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.code).to.eql(100); // jsonDate.value,value=code
});// 使用Content-Type头断言
pm.test("是否存在Content-Type头", function () {
pm.response.to.have.header("Content-Type");
});// 响应时间小于200ms
pm.test("响应时间", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});// 响应状态码
pm.test("响应状态码", function () {
pm.response.to.have.status(200);
});// 状态码范围
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});