Postman 中不同类型的断言
Postman中有不同类型的断言。我们可以在收到的响应的不同部分添加断言。下面列出了一些断言类型-
响应代码断言
pm.test["Status Code is 200"], function(){ pm.response.to.have.status(200) })
如果响应代码为200,则上述断言通过。
pm.test["Status is OK"], function(){ pm.response.to.have.property('status', ' OK') })
上述断言应用于Response属性-值为OK的状态。
响应时间断言
pm.test("Response time below 600 milliseconds", function () { pm.expect(pm.response.responseTime).to.be.below(600) })
如果响应时间低于600毫秒,则上述断言通过。
响应格式断言
pm.test("响应为JSON类型 ", function(){ pm.response.to.be.json; })
如果Response是JSON类型,则上述断言通过。
对响应头断言
pm.test("Header Of Response", function () { pm.response.to.have.header("Content-Encoding") })
如果Response具有Content-EncodingHeader,则上述断言通过。
对响应文本断言
pm.test("Response", function () { pm.expect(pm.response.text()).to.include("Postman") })
如果Response包含文本Postman,则上述断言通过。