postman之Newman生成html报告(生成报告与postman测试情况不符)
参考链接:https://www.cnblogs.com/miniren/p/5607861.html
https://blog.****.net/YZF_DD/article/details/84998505
Newman安装
postman官方文档https://learning.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman/
newman官方文档:http://blog.getpostman.com/2015/04/09/installing-newman-on-windows/
第一步: 安装NodeJs
下载 NodeJs. 到下载地址下载 合适版本的node.exe即可。
下载地址: https://nodejs.org/download/
把node.exe的目录加入到环境变量中。假设node.exe位于 E:\nodejs\node.exe。那么将E:\nodejs加入到环境变量即可。
打开cmd,输入node,如果没有报错,而是显示“>”,说明node安装成功。
第二步:安装NPM
NPM是NodeJs的包管理器,类似于python的setuptools。
下载NPM:git clone --recursive git://github.com/isaacs/npm.git
进入到npm文件夹,然后打开cmd。
在cmd中执行:node cli.js install npm –gf
然后再任意地方,打开cmd,输入“npm”,没有报错说明NPM安装成功。
第三步:安装Newman
打开cmd,输入:npm install -g newman
(以上安装步骤可以参考上面的链接,写的比较好,大家可以看下)
第四步:执行测试用例集,并生成测试报告
newman run XXX.json -r html --reporter-html-export 导出的目录
打开报告查看结果,与postman中不符,共87个接口都错了?但在postman中是正确的
这就很奇怪了,后来查找newman命令中看到
-k, --insecure Disable strict ssl
添加上-k,问题完美解决了。-k是在执行集合时禁用严格ssl,其实也是证书的问题。
补充:当我们postman中使用了环境变量或全局变量,要生成报告时必然要加上这些变量,如下步骤即可完美导出报告:
a.下载我们的环境变量,导出我们的接口测试集合(如:我这里都下载到了D盘中)
b.打开D盘,在地址栏输入cmd,输入我们的命令即生成newman文件夹,里面有我们需要的报告哈
命令格式:newman run 接口集合文件.json -e 环境变量.json -k -r html
全局环境与上面的同步,故这里不再赘述!
附上newman的命令说明,供大家参考:
-h, --help output usage information
-V, --version output the version number
-c, --collection [file] Specify a Postman collection as a JSON [file]
-u, --url [url] Specify a Postman collection as a [url]
-f, --folder [folder-name] Run a single folder from a collection. To be used with -c or -u
-e, --environment [file] Specify a Postman environment as a JSON [file]
--environment-url [url] Specify a Postman environment as a URL
-E, --exportEnvironment [file] Specify an output file to dump the Postman environment before exiting [file]
-d, --data [file] Specify a data file to use either json or csv
-g, --global [file] Specify a Postman globals file [file]
-G, --exportGlobals [file] Specify an output file to dump Globals before exiting [file]
-y, --delay [number] Specify a delay (in ms) between requests
-r, --requestTimeout [number] Specify a request timeout (in ms) for requests (Defaults to 15000 if not set)
-R, --avoidRedirects Prevents Newman from automatically following redirects
-s, --stopOnError Stops the runner with code=1 when a test case fails
-j, --noSummary Doesn't show the summary for each iteration
-n, --number [number] Define the number of iterations to run
-C, --noColor Disable colored output
-S, --noTestSymbols Disable symbols in test output and use PASS|FAIL instead
-k, --insecure Disable strict ssl
-l, --tls Use TLSv1
-N, --encoding [encoding-type] Specify an encoding for the response. Supported values are ascii,utf8,utf16le,ucs2,base64,binary,hex
-x, --exitCode Continue running tests even after a failure, but exit with code=1. Incompatible with --stopOnError
-o, --outputFile [file] Path to file where output should be written [file]
-O, --outputFileVerbose [file] Path to file where full request and responses should be logged [file]
-t, --testReportFile [file] Path to file where results should be written as JUnit XML [file]
-i, --import [file] Import a Postman backup file, and save collections, environments, and globals [file] (Incompatible with any option except pretty)
-p, --pretty Enable pretty-print while saving imported collections, environments, and globals
-H, --html [file] Export a HTML report to a specified file [file]
-W, --whiteScreen Black text for white screen
-L, --recurseLimit [limit] Do not run recursive resolution more than [limit] times. Default = 10. Using 0 will prevent any variable resolution
Newman is a command-line collection runner for Postman. You must specify a collection file or a collection URL to run newman
A collection file or URL is mandatory