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') })
上述斷言應用於響應屬性 - 狀態,值為 OK。
對響應時間進行斷言
pm.test("Response time below 600 milliseconds", function () { pm.expect(pm.response.responseTime).to.be.below(600) })
如果響應時間低於 600 毫秒,則上述斷言透過。
對響應格式進行斷言
pm.test("Response is of JSON type ", function(){ pm.response.to.be.json; })
如果響應為 JSON 型別,則上述斷言透過。
對響應頭進行斷言
pm.test("Header Of Response", function () { pm.response.to.have.header("Content-Encoding") })
如果響應具有 Content-Encoding 頭,則上述斷言透過。
對響應文字進行斷言
pm.test("Response", function () { pm.expect(pm.response.text()).to.include("Postman") })
如果響應包含文字 Postman,則上述斷言透過。
廣告