『接口测试干货』| Newman+Postman接口自动化测试完整过程

📝 面试求职: 「面试试题小程序」内容涵盖 测试基础、Linux操作系统、MySQL数据库、Web功能测试、接口测试、APPium移动端测试、Python知识、Selenium自动化测试相关、性能测试、性能测试、计算机网络知识、Jmeter、HR面试,命中率杠杠的。(大家刷起来…)

📝 职场经验干货:

软件测试工程师简历上如何编写个人信息(一周8个面试)

软件测试工程师简历上如何编写专业技能(一周8个面试)

软件测试工程师简历上如何编写项目经验(一周8个面试)

软件测试工程师简历上如何编写个人荣誉(一周8个面试)

软件测试行情分享(这些都不了解就别贸然冲了.)

软件测试面试重点,搞清楚这些轻松拿到年薪30W+

软件测试面试刷题小程序免费使用(永久使用)


1 Newman简介

Newman是Postman的一个扩展库(NodeJs库);

Newman+Postman可完成接口自动化测试工作;

Postman导出的JSON格式文件可通过Newman的命令行执行;

因为Postman运行后只有概要结果,没有像其他自动化测试框架那么完美漂亮的测试报告样式,所以引入了Newman;

Newman可快速完成集合的运行,构造自动化以及持续集成工作。

2 如何安装Newman?

2.1 安装NodeJs

下载地址:NodeJs;

下载后直接双击运行即可node-v20.10.0-x64.msi;

在这里插入图片描述

2.2 安装Newman

直接命令行输入以下命令即可:

npm install -g newman
C:\Windows\System32>npm install -g newman
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

added 118 packages, and audited 119 packages in 15s

9 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 7.19.1 -> 10.2.4
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.2.4
npm notice Run npm install -g npm@10.2.4 to update!

注意安装时要以管理员身份打开,不然会报错:

C:\Users\Administrator>npm install -g newman
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Program Files\nodejs\node_cache\_cacache\tmp\9c4058f4
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/newman: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache\_cacache\tmp\9c4058f4'
npm ERR!     at C:\Program Files\nodejs\nod_global\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async [nodeFromEdge] (C:\Program Files\nodejs\nod_global\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:936:19)
npm ERR!     at async [buildDepStep] (C:\Program Files\nodejs\nod_global\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:882:11)
npm ERR!     at async Arborist.buildIdealTree (C:\Program Files\nodejs\nod_global\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:218:7)
npm ERR!     at async Arborist.reify (C:\Program Files\nodejs\nod_global\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:134:5)
npm ERR!     at async Install.install (C:\Program Files\nodejs\nod_

验证Newman是否安装成功:

python 代码解读复制代码'newman' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

问题排查:我们已经安装了node.js了,也已经安装了newman,其他都ok了。但还是不行查看node版本也是好的;

在这里插入图片描述

2.2 解决Newman不是内部命令

根据上边的提示,我们已经做好了很多工作,但是还是不行;

这里需要配置node.js的一些环境变;

在node.js的安装目录下新建两个文件夹如下node_global和node_cache:

作者:虫无涯

打开系统环境变量,新增NODE_PATH变量:

NODE_PATH
D:\nodejs\node_modules

在这里插入图片描述
在系统环境变量的path新增:%NODE_PATH%:

链接:https://juejin.cn/post/7304867327752339466

打开用户环境变量,修改path中的npm路径为:D:\nodejs\node_global:

来源:稀土掘金
在这里插入图片描述

重启电脑、重启电脑、重启电脑(重要的事情说三遍)。
验证newman是否安装成功:

newman -h
newman --version

在这里插入图片描述

3 Newman使用

3.1 Newman如何运行集合?

从postman中将脚本导出,集合-右键-三个点-【Export】:

在这里插入图片描述

导出为JSON格式文件即可:

在这里插入图片描述
我们导出的文件为:test.postman_collection.json;

直接命令行执行以下命令运行脚本:

newman run test.postman_collection.json

运行结果如下:

C:\Users\Administrator\Desktop>newman run test.postman_collection.json
newman

test

→ zentao
  POST http://127.0.0.1/zentao/api.php/v1/tokens [201 Created, 1.29kB, 1997ms]
  √  状态码为201

┌─────────────────────────┬─────────────────────┬─────────────────────┐
│                         │            executed │              failed │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│              iterations │                   10 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│                requests │                   10 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│            test-scripts │                   10 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│      prerequest-scripts │                   00 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│              assertions │                   10 │
├─────────────────────────┴─────────────────────┴─────────────────────┤
│ total run duration: 2.1s                                            │
├─────────────────────────────────────────────────────────────────────┤
│ total data received: 44B (approx)                                   │
├─────────────────────────────────────────────────────────────────────┤
│ average response time: 1997ms [min: 1997ms, max: 1997ms, s.d.: 0µs] │
└─────────────────────────────────────────────────────────────────────┘

在这里插入图片描述

3.2 如何查看帮助文档?

使用以下命令即可:

newman -h
或
newman --help

                
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值