使用git管理,使用postman执行自动化测试脚本。
功能需求
- 支持同域名接口的cookie同步
- 支持测试脚本的分支,循环
- 支持测试脚本的导入导出
- 支持环境变量
- 支持批量数据集测试
现状
现有的yapi不满足接口测试功能需求。
postman工具满足接口测试功能需求。
使用postman工具需要一定的js能力。
postman接口自动化测试
需求:请求接口A,如果A的响应值大于9则请求接口C,否则请求接口B。
新建环境变量集合local
,下面新建环境变量host
,值为http://localhost:3000
。
新建Collection接口自动化
,下面新建Get请求请求A
,其中请求地址为{{host}}/A
,属性Tests
内容为
pm.test("requestA is OK", ()=>{
if(responseCode.code === 200){
const aValue = pm.response.value;
pm.environment.set("aResponse", aValue);
if(aValue > 9){
postman.setNextRequest("请求B");
}
else{
postman.setNextRequest("请求C");
}
pm.response.to.have.status(200);
}
else{
pm.response.to.not.have.status(200);
}
});
新建建Get请求请求B
,其中请求地址为{{host}}/B
,属性Tests
内容为
pm.test('requestB is OK', ()=>{
pm.response.to.have.status(200);
})
新建建Get请求请求C
,其中请求地址为{{host}}/C
,属性Tests
内容为
pm.test('requestC is OK', ()=>{
const aValue = pm.environment.get("aResponse");
if(aValue > 9){
pm.response.to.be.ok;
}
else{
pm.response.to.not.be.ok;
}
})
执行Runner,选择接口自动化
,选择Enviroment为local
,点击Start Run
即可。
右键Collection接口自动化
,可以导出测试脚本给git管理。
下载环境变量集合给git管理。
参考链接:
https://segmentfault.com/a/1190000014144322
https://learning.getpostman.com/docs/postman/collection_runs/intro_to_collection_runs
网友评论