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

如图:

相关推荐
Luminbox紫创测控2 小时前
太阳光模拟器在汽车智能玻璃的运用
测试工具·汽车
西瓜程序猿4 小时前
如何将纸质版礼薄转换为电子礼薄?可以使用记了么
测试工具·创业创新
123过去6 小时前
crunch使用教程
linux·测试工具·安全
123过去11 小时前
samdump2使用教程
linux·测试工具·安全
测试199821 小时前
使用Python自动化生成接口测试用例
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
lifewange1 天前
postman接口自动化如何进行参数化
数据库·自动化·postman
妖萌妹儿1 天前
postman怎么做参数化批量测试,测试不同输入组合
开发语言·javascript·postman
lifewange1 天前
Cypress是什么
测试工具
川石课堂软件测试1 天前
涨薪技术|Prometheus使用Recoding Rules优化性能
功能测试·测试工具·jmeter·mysql·面试·单元测试·prometheus