postman的测试集合、接口测试及断言

一、postman测试集合(测试套件)

1.新建一个测试集合

2.编辑测试套件的名字及注释信息

3.设置测试集合的公共参数,用到的时候可以直接通过key调用,如:{{url}}

 

二、通过postman进行接口测试

三、postman对接口的断言

 

var jsonData=JSON.parse(responseBody)
//动态参数
postman.setEnvironmentVariable('token',jsonData.data.token)

//判断响应状态码是否200
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
//判断返回数据中是否包含status字段
pm.test("响应数据中是否包含status",function(){
    pm.expect(pm.response.text()).to.include('status')
})

pm.test("Body is correct",function(){
    pm.response.to.have.body("response_body_string")
})
//判断响应头中是否包含Content-Type
pm.test("响应头中包含Content-Type", function () {
    pm.response.to.have.header("Content-Type");
});

//判断响应时间是否小于200ms
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});


tests["验证返回数据ItemTotalPrice是否OK"]=jsonData.data.ItemTotalPrice===229

tests["验证返回数据AddressID是否OK"]=jsonData.data.DefaultAddress.AddressID===39732

tests["验证返回数据ReceiveName是否OK"]=jsonData.data.DefaultAddress.ReceiveName==="aa"

tests["验证返回数据Mobile是否OK"]=jsonData.data.DefaultAddress.Mobile==="15908168410"
常用的postman断言解释对应脚本
Response body:Contains string response包含字符串 tests["Body matches string"] = responseBody.has("string_you_want_to_search");
Response body:Is equal to a string response body等于指定字符串 tests["Body is correct"] = responseBody === "response_body_string";
response body:JSON value check json解析key的值进行校验 tests["Your test name"] = jsonData.value === 100;
status code:Code is 200 判断状态码 tests["Status code is 200"] = responseCode.code === 200;
status code:code name has string 检查code name 是否包含内容 tests["Status code name has string"] = responseCode.name.has("Created");


posted @ 2019-01-23 14:48  燕鸻  阅读(2828)  评论(0)    收藏  举报