postman.setEnvironmentVariable(“key”, “value”);
Pm.enviroment.get(“key”,”value”) //nativa app特有语法
Postman.clearEnviromentVariable(“key”);
Pm.enviroment.unset(“key”) //nativa app特有语法
postman.setGlobalVariable(“key”, “value”);
Pm.globals.get(“key”,”value”) //nativa app特有语法
Postman.clearGlobalVaricale(“key”);
Pm.globals.unset(“key”) //nativa app特有语法
方法1:
pm.test(“connection Established”, function () {
pm.response.to.have.status(200);
});
方法2:
tests[“Status code is 200”] = responseCode.code == 200;
pm.test(“Body matches string”, function () { pm.expect(pm.response.text()).to.include(“string_you_want_to_search”);
});
方法1:
var res = JSON.parse(responseBody);
tests[“rsp的值是否为操作成功”] = res.rspInf == “操作成功”;
Tests[“判断V的值是否正确”]=res.V==””
tests[“判断data的第二个元素的值(loginTime)是否正确”] = res.data.loginTime === 1548607006000;
方法2:
pm.test(“判断psCd是否=00000”, function () {
var res = pm.response.json();
pm.expect(res.rsCd).to.eql(“00000”);
});
pm.test(“判断role是否=admin”, function () {
var jsonData = pm.response.json();
pm.expect(jsonData.data.role).to.eql(“admin”);
});
方法1:
pm.test(“Response time is less than 200ms”, function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
方法2:
tests[“Response time is less than 200ms”] = responseTime < 200;
var res = JSON.parse(responseBody); // 先获取到返回的json数据
tests[“判断loginTime的值的类型是否是number”] = typeof(res.data.loginTime) === “number”;
tests[“判断rsCd的值的类型师是否是string”] = typeof(res.data.loginTime) == “number”;
// 比较常用的集中类型:number、string、object、array、boolean、undefined
tests[“判断返回的元素中是否有data”] =responseBody.has(“data”);
tests[“判断返回的元素中是否有rsCd”] =responseBody.has(“rsCd”);
var jsonObject = xml2Json(responseBody);
var data = JSON.parse(responseBody);
tests[“Your test name”] = data.value === 100;
tests[“Content-Type is present”] = postman.getResponseHeader(“Content-Type”);
tests[“Status code name has string”] = responseCode.name.has(“Created”);
tests[“Successful POST request”] = responseCode.code === 201 || responseCode.code === 202;