Postman之newman

系列文章目录
1.Postman之安装及汉化基本使用介绍
2.Postman之变量操作
3.Postman之数据提取
4.Postman之pm.test断言操作
5.Postman之newman

Postman之newman

newman可以理解为,没有命令行的postman,把写好的测试脚本直接在命令行中运行,newman依赖于node环境,因此,需要先安装好node再安装newman

1.基础环境node安装

首先通过官网下载node

也可以通过网盘分享的文件下载:node-v22.11.0-x64.msi

链接: https://pan.baidu.com/s/1TbNMD79NbgcTpPjsEi7jbQ?pwd=b6ke 提取码: b6ke

--来自百度网盘超级会员v2的分享

windows下载后,双击文件运行一直下一步,傻瓜式安装即可:

如图:则表示安装成功

1.1.配置环境变量

1.在开始栏中搜索环境变量,点击进入即可

2.双击path,新建环境变量输入:node的安装路径


在cmd命令行中输入:

bash 复制代码
#查看node版本
node -v
#查看npm版本
npm -v
#切换为淘宝镜像,官网镜像下载速度很慢
npm config set registry https://registry.npmmirror.com/

如图即可:

1.2.安装newman和html报告组件

bash 复制代码
#全局安装newman
npm install -g newman
bash 复制代码
#全局安装html报告组件
npm install -g newman-reporter-html

2.newman运行

newman使用流程:在已经装好环境的情况下,首先需要在postman上将请求组成的集合、所有用到的变量全部导出,在命令行中执行命令

运行测试即可。

首先我先将需要通过newman运行的集合,整个导出来,如图:

然后在cmd中执行命令:

bash 复制代码
#			postman导出的脚本文件路径
newman run test.postman_collection.json

如图演示:只运行脚本,不生成报告等

newman还有很多参数:

bash 复制代码
#指定环境变量
-e
#指定全局变量
-g
#指定外部参数化文件
-d
#指定迭代次数
-n
#指定运行后报告的类型可以是:xml、json、html、htmlextra
-r
#生成报告并指定报告的存储位置,以下分别是,html、json、xml、htmlextra报告
--reporter-html-export test.html
--reporter-json-export test.json
--reporter-xml-export test.xml
--reporter-htmlextra-export test.html

例子:

首先我们要先把需要的环境变量 、全局变量、以及脚本导出来,如图



把需要的东西都准备好后,输入命令执行即可

bash 复制代码
newman run test.postman_collection.json -e mytest.postman_environment.json -g workspace.postman_globals.json -d test.csv -n 1 -r html --reporter-html-export test.html

如图:

相关推荐
123过去36 分钟前
crackle使用教程
linux·网络·测试工具·安全
灵翼飞航科技有限公司1 小时前
无人机动力系统测试台简易校准方案(注意事项与维护建议)
测试工具·无人机
尘中客2 小时前
Postman进阶实战:优雅调试带 GZIP 压缩与百KB级复杂嵌套 JSON 的 RESTful API
json·postman·restful·php开发·gzip解压
程序员小远14 小时前
Jmeter基础:Jmeter聚合报告详解
自动化测试·软件测试·python·测试工具·jmeter·测试用例·压力测试
123过去16 小时前
rcracki_mt使用教程
linux·网络·测试工具
@zulnger19 小时前
自动化测试框架:Selenium剖析(1.1)
selenium·测试工具
程序员三藏21 小时前
软件测试:白盒测试详解
自动化测试·软件测试·python·测试工具·职场和发展·单元测试·测试用例