pm.resonse.to pm.response pm.test和pm.expect
//状态返回码判断
pm.test('status 200', function(){
pm.response.to.have.status(200);
});
//状态返回值判断
pm.test('status string OK', function(){
pm.response.to.have.status("OK")
});
//返回header的key来判断
pm.test('header have key Date ', function(){
pm.response.to.have.header('Date')
});
//返回header的key-value来判断
pm.test('header have key "Content-Encoding" ', function(){
pm.response.to.have.header('Content-Encoding', 'gzip')
});
//返回的body有值
pm.test('test body', function(){
pm.response.to.have.body()
});
//返回的body有值对应
pm.test('test body', function(){
pm.response.to.have.body("body中含有的所有字符")
});
//匹配某个字符
pm.test("Body matches string '请求成功'", function () {
pm.expect(pm.response.text()).to.include('请求成功');
});
//匹配json格式
pm.test('test', function(){
var jsonData = pm.response.json();
console.log(jsonData['desc']); //控制台输出对应值
// pm.expect(jsonData['desc'])=='请求成功'; // 第一种方法
pm.expect(jsonData['desc']).to.eql('请求成功'); //第二种方法
});