postman 斷言:
斷言請(qǐng)求結(jié)果狀態(tài)碼:
status code: Code is 200
pm.test("Status code is 200", function () { pm.response.to.have.status(200);});
斷言請(qǐng)求結(jié)果包含內(nèi)容:
Response body: Contains string
pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search");});
在控制臺(tái)打印信息:
console.log(pm.response.json())
console.error('global.site', pm.globals.get("site_id"))
將response的結(jié)果設(shè)置為全局變量:
var data=pm.response.json(); //將響應(yīng)數(shù)據(jù)轉(zhuǎn)化為json格式
pm.globals.set("site_id", data[1].id); //設(shè)置為全局變量