Postman中的断言方式

1、code is 200:断言 http 状态码为 200

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

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

});

2、contains string:断言响应结果包含指定的字符串

pm.test(“Body matches string”, function () {

        pm.expect(pm.response.text()).to.include(“自定义指定字符串”);

});

3、json value check:检查报文中的 json 值

pm.test(“Your test name”, function () {

        var jsonData = pm.response.json();

        pm.expect(jsonData.value).to.eql(100); # 转json格式,检查value属性值为100

});

4、is equal to a string:断言响应结果等于指定的字符串

pm.test(“Body is correct”, function () {

        pm.response.to.have.body(“指定的字符串”);

});

5、Content Type header check:断言报文头中是否包含 Content Type 字段

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

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

});

6、response time is less than 200ms:断言接口响应时间小于 200ms

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

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

});

7、Successful POST request:断言响应码在指定范围内,即 http 状态码在列表[201,202]中

pm.test(“Successful POST request”, function () {

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

});

8、Code name has string:断言响应码包含指定的字符串,请求状态字符为OK

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

        pm.response.to.have.status(“OK”);

});

Postman中的断言方式

来源:橘啊橘啊

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年9月11日
下一篇 2022年9月11日

相关推荐