1. newman 命令行方式运行Collection
- 选中Collection --》 点击... ---》Export ---》选择Collection Format。(导出之后是 .json格式,例如:OpenAPI-Gists.postman_collection.json)或者选中Collection--》Share---》Collection Link---》复制link
- 下载所有环境变量文件Download Environment
- 下载全局变量文件Download as JSON
# 安装 newman
npm install -g newman
newman --version # 3.5.2
npm update -g newman # 升级到最新的版本3.8.3
# newman命令行运行导出的collection.json或者collection link
newman run OpenAPI-User.postman_collection.json -e gitee.com.postman_environment.json
# -e <source> --environment, Specify an environment file path or URL 指定测试环境
# --global-var 指定全局变量,可以指定多个例如:--global-var "key1=value1" --global-var "key2=value2"
- 报错1: .json文件中postman请求中引用的环境变量和全局变量找不到---》通过添加参数指定环境变量和全局变量解决。
- 报错2: ReferenceError:pm is not defined---》通过升级 newman 到最新版本后解决了。
2. Using Newman as a NodeJS module
var newman = require('newman'); //加载newman模块
// call newman.run to pass `options` object and wait for callback
// options对象,由很多属性键值对组成
newman.run({
collection: require('./sample-collection.json'), // 加载Colllection文件
reporters: 'cli', // Available reporters: cli, json, html and junit. 指定输出方式
environment: require('./gitee.com.postman_environment.json'), //加载环境文件
globals: require('./globals.postman_globals.json'), //加载全局变量文件
iterationCount: 1 //重复次数,默认1
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!'); // 始终输出此结束语
});
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。