一、数据校验
//定义变量
var jsonData = pm.response.json();
//检查状态为200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
//代码名称包含一个字符串
pm.test("Status code name has string", function () {
pm.response.to.have.status("Created");
});
//成功的POST请求状态码
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201,202]);
});
//检查返回的内容为json格式
pm.test("response must be valid json", function () {
pm.response.to.be.json;
});
//返回内容中包含is_open (nationality_id字段的值为is_open?)
pm.test("ResponseBody has nationality_id", function () {
pm.expect(pm.response.text()).to.include("nationality_id");
});
//检查响应正文是否包含字符串