postman是基于javascript语言编写的,而导出的json格式的postman脚本也无法直接在服务器运行,它需要在newman中执行(可以把newman看做postman脚本的运行环境)
所以要实现在windows的cmd窗口或者linux系统中直接以命令的方式执行脚本,我们需要安装node.js,然后再在此基础上安装newman
了解newman:https://learning.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman/
一.windows下安装
1.安装node.js
到官网下载最新的windows版node.js,直接安装即可(不用自己去配置环境变量,安装完成后会自动配好)

安装完成后,打开cmd窗口,输入 node -v,如下出现版本号表示安装成功

2.安装newman
可以通过npm来安装newman,npm 是 JavaScript 的包管理工具,并且是 Node.js 平台的默认包管理工具。通过 npm 可以安装、共享、分发代码,管理项目依赖关系。
一般安装好node.js后会默认安装好npm的,直接使用即可
打开cmd窗口,执行以下命令
npm install -g newman --registry=https://registry.npm.taobao.org
安装完成后,输入newman -v,如下出现版本号表示安装成功

3.如果想生成html格式的测试报告,还需要安装 newman-reporter-html
npm install -g newman-reporter-html

newman的常用命令
官方的文档介绍如下:https://learning.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman/
4、newman执行postman导出脚本
postman导出脚本后存放在一个目录下

cmd命令窗口进入到该目录下,后执行 newman run 脚本 (无报告)
如果想要有报告,执行这条命令
newman run 脚本 -reporters html --reporter-html-export report-html.html (--reporter-htm 表示生成html报告,report-html.html 表示报告名称)
报告内容