postman自动记录执行结果
问题
-
解决场景测与没测,结果对与不对纠纷
-
避免测试时结果是对的,后期代码改动造成结果错误导致的内容不确定
-
同一场景下,历史逻辑、返回结果的反查
极简方案
1、在history tab中,打开save Response 选项,自动记录历史请求和response
完善方案
将每次请求、结果都自动保存到本地文件中,以备查用
-
https://github.com/sivcan/ResponseToFile-Postman 结合这个本地服务实现保存功能
使用方法:
Put all the requests you want to write the responses for, under this collection.
1、Clone the following repository to your machine - https://github.com/sivcan/ResponseToFile-Postman or use the following command - git clone https://github.com/sivcan/ResponseToFile-Postman
-
Navigate into the directory and install the dependencies. Use the following command: npm i
如果没有npm,通过安装nodejs一起安装https://nodejs.org/en/
3、Run the local server. Use the following command: node script.js
Now, the responses for every request which is a part of this collection will be written to the Responses folder inside the project repo. You can modify the local server's code to change the file location.
Run your requests through builder / run through collection runner and store your data locally.
上面整个项目入口代码在 script.js文件中
-
可以对默认的文件存储路径进行修改
以下修改
-
/*
-
生成年月日用于按日期存储文件
-
*/
-
function getTimeInfo() {
-
var date = new Date;
-
var year = date.getFullYear();
-
var month = date.getMonth() 1;
-
month = (month<10 ? "0" month:month);
-
var day = date.getDate();
-
return (year.toString() '-' month.toString() '-' day.toString());
-
}
-
-
-
// Modify the folder path in which responses need to be stored
-
folderPath = './Responses/' getTimeInfo()'/',
-
修改生成文件的扩展名
postman中配置test脚本
-
// Please read the documentation on the right side (collection level documentation) to learn about how to use this collection ->
-
-
// The opts for the server, also includes the data to be written to file
-
let opts = {
-
requestName: request.name || request.url,
-
fileExtension: 'json',
-
mode: 'writeFile', // Change this to any function of the fs library of node to use it.
-
uniqueIdentifier: true,
-
requestData:pm.request.body.raw || request.url,
-
responseData: pm.response.text()
-
-
};
-
-
pm.sendRequest({
-
url: 'http://localhost:3000/write',
-
method: 'POST',
-
header: 'Content-Type:application/json',
-
body: {
-
mode: 'raw',
-
raw: JSON.stringify(opts)
-
}
-
}, function (err, res) {
-
console.log(res);
-
});
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgfjiae
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01