Postman 之 newman 导出测试报告

  • 安装
  • 全局安装
  • 本地安装
  • 生成测试报行
  • 1. 从`postman`导出`collections`
  • 2、命令行运行 `newman` 生成报告。
  • 2.1. 执行看效果
  • 2.2. 安装 `newman-reporter-html`
  • 2.3. 安装`newman-reporter-htmlextra`
  • 写个批处理方便以后用
  • 进一步优化
  • 把批处理文件改造一下
  • 创建定时任务
  • 参考资料


安装

  1. 安装nodejs见: Nodejs 学习笔记 下载安装
  2. 安装npm见:npm install 学习笔记
  3. 安装newmannewman 是Postman 的一个命令行工具,这里 newman文档 介绍还是满详细的。
    另外还有不少官方的 官方 newman 博文介绍 想细品的可以看看。

全局安装

>npm install -g newman

查看版本

newman -v

本地安装

就是不加 -g

>npm install newman

使用时需要添加临时环境变量,或直接进入当前项目\node_modules\.bin目录执行。

E:\temp>set path=.\node_modules\.bin;%path%
E:\temp>newman -v
5.2.4

生成测试报行

总共分两步:1、从postman导出collections。 2、命令行运行 newman 生成报告。

1. 从postman导出collections

mputy导出session 导出postman_postman

mputy导出session 导出postman_postman_02

2、命令行运行 newman 生成报告。

2.1. 执行看效果

mputy导出session 导出postman_npm_03

2.2. 安装 newman-reporter-html

用于生成HTML报告。同样我使用本地安装。

npm install newman-reporter-html

执行以下命令会在当前目录自动生成 【newman】文件夹存放报告

>newman run temp.postman_collection.json -r html

生成的报告位置、效果如下图,过于简单。。。

mputy导出session 导出postman_newman_04

mputy导出session 导出postman_mputy导出session_05

2.3. 安装newman-reporter-htmlextra

安装这个扩展可以导出更详细的测试报告。
官方文档中有各种参数,可以排除这、排除那。。。我们直接导个完整的看看。

npm install newman-reporter-htmlextra

执行生成报告

newman run temp.postman_collection.json -r htmlextra

报告效果

mputy导出session 导出postman_npm_06

写个批处理方便以后用

如果有中文,记得bat要保存成 ANSI编码

cd  %~dp0
set path=.\node_modules\.bin;%path%
newman run temp.postman_collection.json -r htmlextra

进一步优化

  1. 我要配个定时任务。
  2. 每天早上来,最新的报告已经自动打开,看过没问题即可关掉。不用去翻阅。

把批处理文件改造一下

  1. main.bat 这个给定时任务调用。
call 1-执行测试导出报告.bat
call 2-打开最新报告.bat
  1. 1-执行测试导出报告.bat 负责生成报告
set path=.\node_modules\.bin;%path%
newman run temp.postman_collection.json -r htmlextra
  1. 2-打开最新报告.bat负责打开最新的报告文件
cd newman
for /f %%a in ('dir /o-d /tc /b .') do (
set filename=%%~na%%~xa
goto end
)
:end
start %filename%

效果如下

mputy导出session 导出postman_测试报告_07

创建定时任务

都是中文,就不多介绍了。

mputy导出session 导出postman_npm_08

mputy导出session 导出postman_npm_09


顺便说一下,这里填写脚本(应用)运行的位置。

mputy导出session 导出postman_npm_10


如果不设置这个也可以在bat前面添加

%~d0
cd  %~dp0

参考资料

Nodejs 学习笔记 下载安装npm install 学习笔记

newman文档官方 newman 博文介绍newman-reporter-htmlextra文档