【Postman】Newman安装与环境配置完整版(内含安装过程中遇到的问题与解决方案)

概要

  • Newman:一款基于nodejs开发的可以运行Postman脚本的工具,并且可以生成测试报告。
  • 本文介绍了Newman安装全过程,包括以下三个步骤: 1、nodejs的安装与环境配置。
    2、安装newman。
    3、安装newman-reporter-html。
  • 另外还有安装过程中遇到的一些问题与解决方案。

Newman安装三步走

一、nodejs安装与环境配置

1、安装

(1)步骤
下载地址: http://nodejs.cn/download/
在这里插入图片描述
下载完成后双击运行安装包,如【nnode-v18.17.0-x64.msi】
点击下一步完成安装过程。
(2)测试
打开cmd窗口运行node -v,结果如下图所示:
在这里插入图片描述

2、环境配置

(1)配置npm的全局模块的存放路径以及cache的路径
在Nodejs安装目录下新建node_cache和node_global空文件夹,如下:
在这里插入图片描述

(2)打开cmd 窗口分别运行以下两条命令
注意:将路径改为你自己新建的以上两个文件夹的位置。

npm config set prefix "D:\Nodejs\node_global"
npm config set cache "D:\Nodejs\node_cache"

在这里插入图片描述

(3)右键此电脑→属性→高级系统设置→环境变量
添加系统变量NODE_PATH值为node_modules文件夹的路径,如:D:\Nodejs\node_modules
在这里插入图片描述
编辑系统变量Path添加%NODE_PATH%
在这里插入图片描述
编辑用户变量Path中的npm路径,将其改为node_global文件夹的路径,如:D:\Nodejs\node_global
在这里插入图片描述

二、安装newman

1、步骤

打开cmd窗口,运行npm install -g newman
在这里插入图片描述
输入newman -v,出现版本号即为安装成功
在这里插入图片描述

2、问题与解决方案

(1)安装时出现"npm notice Run npm install -g npm@9.8.1 to update!"
如下图所示:
在这里插入图片描述
解决方案:不用管,后面安装newman-reporter-html还需要降低版本。

在这里插入图片描述
(2)安装完后输入newman -v显示“‘newman’ 不是内部或外部命令,也不是可运行的程序或批处理文件。”
如下图所示:
在这里插入图片描述
解决方案:按照本文一中进行nodejs的环境配置。

三、安装newman-reporter-html

1、步骤

降低npm版本,运行命令:npm install npm@6.14.10 -g --no-fund
在这里插入图片描述
运行npm install -g newman-reporter-html --no-fund
在这里插入图片描述

至此完成Newman的安装与配置。

2、问题与解决方案

(1)问题: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.
npm WARN deprecated uuid@3.3.2: 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.
npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)

如下图所示:
在这里插入图片描述
解决方案:参考步骤(1),降低npm版本,运行命令:npm install npm@6.14.10 -g --no-fund
在这里插入图片描述

(2)问题:输入npm install xx后出现:
3 packages are looking for funding
run npm fund for details

在这里插入图片描述
解决方案:在后面加上 --no-fund
在这里插入图片描述

Newman是一款强大的Postman Collection Runner,用于自动化测试API。以下是新版本的安装环境配置的步骤: 1. **下载安装**: - 访问Newman的官方网站 [GitHub](https://www.getpostman.com/docs/newman_installation) 或者通过npm进行安装:在终端中运行 `npm install -g newman` (如果尚未全局安装Node.js,请先安装它)。 2. **环境变量设置**: - 如果你需要在Windows上运行Postman Collection,确保已经安装Postman Desktop,并将Postman的bin目录添加到系统路径中。 - 对于Mac和Linux用户,检查`~/.bashrc`或`.zshrc`文件,确保包含类似下面的行: ``` export PATH=$PATH:/path/to/postman/bin ``` 3. **验证安装**: 使用命令 `newman --version` 检查已安装的新man版本,确认安装成功。 4. **创建Collection**: 在Postman中创建一个新的Collection,这包含了你要自动化的请求序列。 5. **配置文件**: 新建一个JSON文件(如newman.json),指定Collection、数据源(如果需要)、环境等信息。例如: ```json { "collection": "path/to/your/collection.postman_collection", "environment": "path/to/your/environment.postman_environment" } ``` 6. **运行测试**: 使用命令 `newman run newman.json` 运行自动化测试。你可以选择传递额外参数,比如 `-e` 设置特定环境,`-c` 指定不同的Collection。 7. **日志和报告**: Newman会生成详细的测试报告,包括每个请求的状态、响应时间等信息。默认报告位于当前工作目录下。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值