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

如图:

相关推荐
测试老哥14 小时前
Jmeter自动化性能测试常见问题汇总
自动化测试·软件测试·测试工具·jmeter·接口测试·压力测试·性能测试
苦逼IT运维16 小时前
Jenkins + SonarQube 从原理到实战四:Jenkins 与 Gerrit 集成并实现自动任务
运维·git·测试工具·ci/cd·jenkins
测试19981 天前
Web自动化测试:测试用例流程设计
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
敬业小码哥2 天前
记一次:postman请求下载文件的使用方法
测试工具·postman
cxyll12343 天前
postman+newman+jenkins接口自动化
自动化·jenkins·postman
测试老哥3 天前
pytest+requests+allure自动化测试接入Jenkins学习
自动化测试·软件测试·学习·测试工具·职场和发展·jenkins·pytest
让代码飞~3 天前
idea进阶技能掌握, 使用自带HTTP测试工具,完全可替代PostMan
java·http·intellij-idea·postman
Mike_Wuzy3 天前
【音频信号发生器】基本应用
测试工具
程序员三藏3 天前
Selenium+python自动化测试:解决无法启动IE浏览器及报错问题
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例