~postman基础断言方法
postman官方文档:https://learning.getpostman.com/docs/postman/scripts/test_examples/

断言1:检查响应主体是否包含字符串
// 检查响应主体是否包含字符串
pm.test("登录成功", function () {
pm.expect(pm.response.text()).to.include("登录成功");
});断言3:检查JSON值
// 通过json值断言
pm.test("登录成功,code值等于0", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.code).to.eql(100); // jsonDate.value,value=code
});断言4:使用响应头断言
// 使用Content-Type头断言
pm.test("是否存在Content-Type头", function () {
pm.response.to.have.header("Content-Type");
});断言5:响应时间小于200ms
// 响应时间小于200ms
pm.test("响应时间", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});断言6:响应状态码
// 响应状态码
pm.test("响应状态码", function () {
pm.response.to.have.status(200);
});断言7:通过POST请求状态码进行断言
// 状态码范围
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
}); 相关推荐
充满诗意的联盟 2020-08-23
Teamomc 2020-06-28
huimeiad 2020-11-23
82387067 2020-11-03
bbccaaa 2020-11-03
ljsfighting 2020-10-31
小马的学习笔记 2020-10-23
chenhaimeimeng 2020-09-15
82387067 2020-08-15
bbccaaa 2020-07-28
ljsfighting 2020-07-28
ljsfighting 2020-07-18
ljsfighting 2020-07-05
Alassad 2020-06-29
pushTop 2020-06-27
curiousL 2020-06-21
Teamomc 2020-06-12