1.获取接口相应结果 var jsonData = pm.response.json() 2.设置环境变量 pm.environment.set("variable_key", "variable_value"); 3.设置全局变量 pm.globals.set("variable_key", "variable_value"); 4.通过key值获取环境变量 pm.environment.get("variable_key"); 5.通过key值获取全局变量 pm.globals.get("variable_key"); 6.通过key值获取一个变量 pm.variables.get("variable_key"); 7.通过key值注销一个环境变量 pm.environment.unset("variable_key"); 8.通过key值注销一个全局变量 pm.globals.unset("variable_key"); 9.向服务端发送请求 pm.sendRequest("url", function (err, res) { console.log(err ? err : res.text());//打印相应结果 }); 10.判断响应状态是否为200 pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); 11.判断response-body包含的字段 pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("k6SLhOSZe-8TFeSp1eRSP0"); }); 12.判断返回的字段值 pm.test("Your test name", function () { var jsonData = pm.response.json(); pm.expect(jsonData.value).to.eql(100); }); 13.判断响应的结果是否等于一串字符串 pm.test("Body is correct", function () { pm.response.to.have.body("response_body_text_string"); }); 14.判断响应头包含的字段 pm.test("Content-Type is present", function () { pm.response.to.have.header("Content-Type"); }); 15.判断响应的时间不高于当前设置的时间(ms) pm.test("Response time is less than 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(200); }); 16.判断响应的状态码是否包含其中 pm.test("Successful POST request", function () { pm.expect(pm.response.code).to.be.oneOf([201, 202,200]); });
|
GMT+8, 2025-1-18 13:05 , Processed in 0.148872 second(s), 19 queries , Gzip On.
Powered by Discuz! X3.5
© 2001-2024 Discuz! Team.