postman+newman自动化测试

1、安装和配置newman:

  1. 安装 Node.js:newman 是一个 Node.js 包,因此在安装之前需要先安装 Node.js。下载地址(https://nodejs.org/zh-cn/download)下载跟你操作系统对应的包,参考菜鸟(https://www.runoob.com/nodejs/nodejs-install-setup.html

  2. 安装 npm:npm 是 Node.js 的包管理器,它用于安装和管理 Node.js 包。当你安装 Node.js 时,npm 通常会一同安装。你可以通过在命令行界面中输入 npm -v 来检查是否安装了 npm,并查看其版本号。

确保已经安装了Node.js和npm,在命令行中运行以下命令来安装newman。

npm install -g newman

安装完成后,可以使用以下命令验证newman是否成功安装:

newman --version

2、导出postman集合为JSON文件:

在postman中,选择你的集合,点击右上角的三个点图标,然后选择"Export"->"Collection",将集合导出为JSON文件。

在存放脚本的路径下 打开cmd  执行newman快速运行API测试。

3、安装HTML插件或HTMLeXtra插件

npm install -g newman-reporter-html
npm install -g newman-reporter-htmlextra

4、生成测试报告:

使用newman运行postman集合并生成测试报告。在命令行中,切换到存储postman集合的JSON文件的目录,并运行以下命令来生成HTML报告:

newman run [collection.json] --reporters html --reporter-html-export [report.html]
newman run [collection.json] --reporters htmlextra --reporter-htmlextra-export [report.html]

在上述命令中,[collection.json]是你的postman集合的JSON文件路径,[report.html]是要生成的报告的文件路径。运行命令后,newman将执行集合中的所有请求,并生成相应的测试报告。

posted @ 2023-06-06 17:15  老板娘来碗三鲜粉  阅读(84)  评论(0)    收藏  举报