postman newman 生成测试报告排版混乱 - 解决方案

一.问题来源

我们在使用reporter-htmlextra-export导出生成测试报告时会出现排版混乱问题,是因为生成的html文件的内联的css样式存在问题

存在问题的css样式:

<link rel="stylesheet" href="https://cdn.datatables.net/v/bs4/dt-1.10.18/datatables.min.css"/>

二.解决方案

1.打开Windows PowerShell

2. 输入指令npm root -g查找全局安装的包的位置

npm root -g

3.根据全局node安装包的位置找到newman-reporter-htmlextra包

4.进入newman-reporter-htmlextra\lib文件夹找到相关文件

newman-reporter-htmlextra\lib

5.通过记事本打开dashboard-template.hbsonly-failures-dashboard.hbs文件修改内联的css,

之前说过下方选中这个内联的css存在问题

选中它,将它替换成下方的引入样式,dashboard-template.hbsonly-failures-dashboard.hbs两个文件都需要这样操作

<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/css/bootstrap.min.css"/>

6.保存完成,重新导出,查看结果 

备注: 此方法是通过更改本地newman-reporter-htmlextra包的源代码实现

### 如何使用 Newman 导出 Postman 的全局变量和环境变量并生成测试报告 在使用 Newman 执行 Postman 集合时,可以通过特定的命令行参数导出全局变量和环境变量,并生成测试报告。以下是详细的实现方法: #### 1. 导出环境变量 Newman 提供了 `-e` 参数用于指定环境变量文件路径,同时可以通过 `--export-environment` 参数将执行过程中使用的环境变量导出到指定路径[^3]。 ```bash newman run your_collection.json -e your_env.json --export-environment exported_env.json ``` 上述命令中: - `your_collection.json` 是 Postman 集合文件。 - `your_env.json` 是环境变量文件。 - `exported_env.json` 是导出的环境变量文件路径。 #### 2. 导出全局变量 Newman 提供了 `--export-global` 参数用于导出全局变量。 ```bash newman run your_collection.json -g your_global.json --export-global exported_global.json ``` 上述命令中: - `your_global.json` 是全局变量文件。 - `exported_global.json` 是导出的全局变量文件路径。 #### 3. 生成测试报告 Newman 默认支持多种格式的报告生成,例如 `cli`、`html` 等。如果需要更丰富的报告样式,可以安装第三方插件,如 `newman-reporter-htmlextra`[^4]。 安装插件: ```bash npm install -g newman-reporter-htmlextra ``` 生成带插件的测试报告: ```bash newman run your_collection.json -e your_env.json -g your_global.json -r htmlextra --reporter-htmlextra-export report.html ``` 上述命令中: - `-r htmlextra` 指定使用 `newman-reporter-htmlextra` 插件生成报告。 - `--reporter-htmlextra-export report.html` 指定生成的 HTML 报告路径。 #### 4. 综合示例 以下是一个完整的命令示例,展示如何同时导出全局变量、环境变量并生成测试报告: ```bash newman run your_collection.json -e your_env.json -g your_global.json --export-environment exported_env.json --export-global exported_global.json -r htmlextra --reporter-htmlextra-export report.html ``` 此命令实现了以下功能: - 使用 `your_env.json` 和 `your_global.json` 文件作为环境变量和全局变量。 - 将执行后的环境变量导出到 `exported_env.json`。 - 将执行后的全局变量导出到 `exported_global.json`。 - 使用 `newman-reporter-htmlextra` 插件生成 HTML 格式的测试报告,并保存为 `report.html`。 ### 注意事项 - 如果集合或脚本中动态修改了环境变量或全局变量,这些修改后的值会反映在导出的文件中[^2]。 - 在某些情况下,可能需要调整超时时间以确保所有请求都能完成。可以使用 `--timeout-request` 或 `--timeout-script` 参数设置请求或脚本的超时时间[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值