以下是在Linux上利用Postman进行接口自动化的步骤:
安装依赖工具
sudo apt update && sudo apt install nodejs npm
npm install -g newman
创建Postman集合
// 检查状态码 pm.test("Status code is 200", function() { pm.response.to.have.status(200); });
配置环境变量(可选)
编写自动化脚本(可选)
const newman = require('newman'); newman.run({ collection: 'path/to/collection.json', environment: 'path/to/environment.json', reporters: 'cli,html', // 生成HTML报告 delayRequest: 1000 // 请求间隔(毫秒) }, function(err, summary) { if (err) console.error(err); console.log(summary); });
执行自动化测试
node run-tests.js
newman run collection.json -e environment.json -r html --reporter-html-export report.html
集成到CI/CD(可选)
说明: