1、检查响应体中是否包含某个字符串
pm.test("检查响应体是否包含王欣欣", function () {
pm.expect(pm.response.text()).to.include("王欣欣");
});
2、将XML格式的响应体转换为Json对象
console.log(xml2Json(responseBody));

3、检查响应体是否等于某个字符串
pm.test("检查响应体是否等于北京", function () {
pm.response.to.have.body("北京");
});
4、检查响应体的Json值
pm.test("检查Json返回值", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.weatherinfo.city).to.eql("北京");
});
5、检查响应体中包含某个header
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});
6、检查响应时间,要求小于200ms
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
7、要求该接口响应code为200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
8、要求code名称当中包含某个字符串
pm.test("Status code name has string", function () {
pm.response.to.have.status("OK");
});
9、要求status code符合某种条件
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([200,201,202]);
});
10、使用轻量级验证器
var schema = {
"items": {
code: {type:"string"},
data: {type:"object"},
totalNum: {type:"number"},
msg: {type:"string"},
tid: {type:"string"}
}
};
var data1 = JSON.parse(responseBody);
// pm.test('Schema is valid', function () {
// pm.expect(tv4.validate(data1, schema)).to.be.true;
// });
tests["Schema is valid"] = tv4.validate(data1, schema)