安装
官方文档:
Newman - Running collections in the command line
1. 安装NodeJs
下载 NodeJs. 到下载地址下载 合适版本的node.exe即可。
下载地址: https://nodejs.org/download/
打开cmd,输入node,如果没有报错,而是显示“>”,说明node安装成功。
备注:安装方法可以参考 深入浅出Node.js(二):Node.js&NPM的安装与配置
2. 安装NPM
NPM是NodeJs的包管理器,类似于python的setuptools。(一般在安装完node.js之后,npm也会同样安装)
下载NPM:git clone --recursive git://github.com/isaacs/npm.git
进入到npm文件夹,然后打开cmd。
在cmd中执行:node cli.js install npm –gf
然后再任意地方,打开cmd,输入“npm”,没有报错说明NPM安装成功。
备注: 可以参考 深入浅出Node.js(二):Node.js&NPM的安装与配置
3. 安装Newman
打开cmd,输入: npm install -g newman
4. 使用newman
打开cmd,然后输入 “newman”,没有报错说明安装成功。
使用
可以参考:
Newman - Running collections in the command line
1. 执行 collection。
newman run {json filesource}//绝对路径比较准确
//(Windows系统后面不需要分号,linux系统需要) 暂时是这样,准确性有待验证
例如:newman run C:\Users\xingzheng\Desktop\dafmng-api.json
2. 直接发送一个request。
表示URL为“
https://www.getpostman.com/collections/cb208e7e64056f5294e5", Environment 为“dev_environment.json”。
newman run https://www.getpostman.com/collections/cb208e7e64056f5294e5 --environment dev_environment.json
3. 设置跑测试的轮数。
表示跑10轮测试。
newman run C:\Users\xingzheng\Desktop\dafmng-api.json -n 10
4. 设置数据文件。
newman run collection.json --environment env.json --iteration-data data.csv --globals globals.json --iteration-count 2 --export-globals globalOut.json --export-environment envOut.json --delay-request 10 --timeout-request 5000 --disable-unicode --suppress-exit-code --ignore-redirects --bail
5. 保存output到文件。
newman run https://a.com/collection.json --environment https://a.com/env.json --reporters cli,html,json,junit --reporter-json-export jsonOut.json --reporter-junit-export xmlOut.xml --reporter-html-export htmlOutput.htm
Newman V2与V3的区别之处
CLI migration table
V2 CLI option | V3 equivalent | V2 option Status |
---|---|---|
-c --collection | N.A | Deprecated (Pass the collection file path without the collection flag) |
-u --url | N.A | Deprecated (Pass the collection file URL without the collection flag) |
--environment-url | N.A | Deprecated (Pass the environment file URL to -e --environment) |
-f --folder | --folder | Deprecated. The V3 folder option has been reduced to --folder |
-d --data | -d --iteration-data | Deprecated |
-n --number | -n --iteration-count | Deprecated |
-i --import | N.A | Deprecated |
-p --pretty | N.A | Discontinued |
-G --exportGlobals | --export-globals | Deprecated |
-E --exportEnvironment | --export-environment | Deprecated |
-y --delay | --delay-request | Deprecated |
-r --requestTimeout | --timeout-request | Deprecated |
-s --stopOnError | --bail | Deprecated |
-j --noSummary | --reporter-cli-no-summary | Deprecated |
-C --noColour | --no-color | Deprecated |
-S --noTestSymbols | --disable-unicode | Discontinued |
-l --tls | N.A | Discontinued |
-x --exitCode | -x --suppress-exit-code | Deprecated |
-w --whiteScreen | N.A | Discontinued |
-o --outputFile | --reporter-json-export | Deprecated |
-t --testReportFile | --reporter-junit-export | Deprecated |
-H --html | --reporter-html-export | Deprecated |
-O --outputFileVerbose | N.A | Discontinued |
-R --avoidRedirects | --ignore-redirects | Deprecated |
NewmanV3命令说明: