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

打开用户环境变量,修改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 │ 1 │ 0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│ requests │ 1 │ 0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│ test-scripts │ 1 │ 0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│ prerequest-scripts │ 0 │ 0 │
├─────────────────────────┼─────────────────────┼─────────────────────┤
│ assertions │ 1 │ 0 │
├─────────────────────────┴─────────────────────┴─────────────────────┤
│ 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

最低0.47元/天 解锁文章
1387

被折叠的 条评论
为什么被折叠?



