鉴权反例:
参数反例:参数为空,参数类型异常,参数长度异常等等情况
错误码覆盖:根据业务而定
其他错误场景:
请求页签
响应页签
Body:接口返回的数据
cookies:响应的cookie信息
headers:响应头
test results:断言的结果
status:200 ok:200是状态码,ok是状态信息
time:223ms:是接口响应的时间
size:373B:响应的字节数
get和post的区别
问题:
解决问题:接口关联:需要手动关联
实现方式:
console.log(responseBody);
// 使用json提取器提取access_token值
// 把返回的字符串格式的数据转换成对象的形式
var result = JSON.parse(responseBody);
console.log(result.access_token);
// 把access_token设置为全局变量
pm.globals.set("access_token", result.access_token);
解决问题:接口关联:需要手动关联
实现方式:
// 使用正则表达式提取器实现接口关联,matcg表示匹配
var resuslt = responseBody.match(new RegExp('"access_token":"(.*?)"'));
console.log(resuslt[1])
// 设置为全局变量
pm.globals.set("access_token", resuslt[1]);
实现方式:
// 手动的获得时间戳
var times =Date.now();
// 设置为全局变量
pm.globals.set("time_now",times);
// 使用正则表达式提取器实现接口关联,matcg表示匹配
var resuslt = responseBody.match(new RegExp('"access_token":"(.*?)"'));
console.log(resuslt[1])
// 设置为全局变量
pm.globals.set("access_token", resuslt[1]);
// 断言
// 状态断言
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// 业务断言
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("access_token");
});
在输出的结果页签的 Test Results中查看结果
在断言中使用自定义动态参数不能使用这种{{xxx}}方式,要使用+号拼接,动态参数使用get a global variable方式获取
可以将接口中的状态断言代码挪动到集合的test中去,接口中的断言只留下业务断言
if (responseBody.search("access_token")!=-1){
// 使用正则表达式提取器实现接口关联,matcg表示匹配
var resuslt = responseBody.match(new RegExp('"access_token":"(.*?)"'));
console.log(resuslt[1])
// 设置为全局变量
pm.globals.set("access_token", resuslt[1]);
}
// 断言
// 业务断言
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include(data.access_token); //data为表名,access_token为列名
});
<html>
<head>
head>
<body>
<error_code>0error_code>
<msg>提现成功msg>
....
body>
html>
请求:get,post,put.delete
响应:1xx信息,2xx成功,3xx重定向(跳转不传值),4xx客户端错误,5xx服务器错误
请求部分包含:
响应部分包含: