postman断言方法

postman一共有8种断言方式

 postman的断言方式

//八种断言方式

1、断言返回码为200(*****)状态断言

pm.test("Status code is 200", function () {

pm.response.to.have.status(200);

});

2、断言返回的结果中包含有指定的字符串(*****)业务断言

pm.test("Body matches string", function () {

pm.expect(pm.response.text()).to.include("tags");

});

3、对返回的结果做json字段检查(*****)业务断言

pm.test("Your test name", function () {

var jsonData = pm.response.json();

pm.expect(jsonData.tags[0].id).to.eql(2);

});

4、断言返回的结果等于一个字符串(*****)业务断言

pm.test("Body is correct", function () {

pm.response.to.have.body("response_body_string");

});

5、断言响应头中包含有指定的响应头

pm.test("Content-Type is present", function () {

pm.response.to.have.header("Content-Type");

});

6、断言相应的时间少于200ms(*****)性能断言

pm.test("Response time is less than 200ms", function () {

pm.expect(pm.response.responseTime).to.be.below(200);

});

7、断言一个post请求返回的状态码是不是在指定的范围内

pm.test("Successful POST request", function () {

pm.expect(pm.response.code).to.be.oneOf([201, 202]);

});

8、断言返回的状态码包含指定的字符串

pm.test("Status code name has string", function () {

pm.response.to.have.status("Created");

});

精确断言

var time = Date.now()

console.log(time)

pm.globals.set("time", time);

首先当请求体里面的数是不固定的时想要精确断言到对应的值时

第一步:在Pre-request Script中设置对应的变量(请求前的操作)

第二步:在请求体中用上对应的全局变量

第三步:精确断言


版权声明:本文为zl3695原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。