首页主机资讯centos中postman如何导出报告

centos中postman如何导出报告

时间2025-12-05 23:09:03发布访客分类主机资讯浏览447
导读:CentOS 中 Postman 导出报告的实用方法 一 准备与导出集合与环境 在 Postman 中将调试通过的 Collection 导出为 .json;如使用环境变量或全局变量,也一并导出为 .json。 将导出的文件上传到 Cen...

CentOS 中 Postman 导出报告的实用方法

一 准备与导出集合与环境

  • Postman 中将调试通过的 Collection 导出为 .json;如使用环境变量或全局变量,也一并导出为 .json
  • 将导出的文件上传到 CentOS 工作目录(如:/opt/postman)。
  • 说明:桌面版 Postman 主要用于手工运行与查看结果;要在 Linux/CentOS 生成文件化报告,通常使用 Newman 在命令行执行集合并导出报告。

二 安装 Newman 与报告插件

  • 安装 Node.js(建议 Node ≥ 14),然后安装 Newman 与报告插件(示例为全局安装):
    • 安装 Newman:npm install -g newman
    • 安装 HTML 报告插件:npm install -g newman-reporter-html
    • 如需更丰富的 HTML 报告,可安装:npm install -g newman-reporter-htmlextra
  • 验证安装:node -v、npm -v、newman -v 能正常输出版本号。

三 生成报告常用命令

  • 基本 HTML 报告
    • newman run collection.json -r html --reporter-html-export report.html
  • 使用环境变量、数据文件
    • newman run collection.json -e env.json -d data.csv -r html --reporter-html-export report.html
  • 使用 htmlextra 生成更美观报告
    • newman run collection.json -e env.json -r htmlextra --reporter-htmlextra-export report.html
  • 常用参数说明
    • -e:环境变量文件;-g:全局变量文件;-d:数据文件(如 CSV);-r:报告类型(如 html/json/cli);–reporter-html-export:指定 HTML 报告输出路径。

四 在 CentOS 查看报告与常见问题

  • 查看报告
    • 安装 firefoxgoogle-chrome-stable,然后用命令行打开报告:firefox report.html 或 google-chrome-stable report.html。
  • 无头环境生成截图或 PDF(可选)
    • 使用 Puppeteer 的无头 Chrome 将 HTML 报告转换为 PDF(示例):
      • 安装:npm i -D puppeteer
      • 保存为 html2pdf.js:
        • const fs = require(‘fs’); const puppeteer = require(‘puppeteer’);
        • (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage();
        • await page.setContent(fs.readFileSync(‘report.html’, ‘utf8’), { waitUntil: ‘networkidle0’ } );
        • await page.pdf({ path: ‘report.pdf’, format: ‘A4’ } ); await browser.close(); } )();
      • 执行:node html2pdf.js
  • 常见问题
    • 命令报找不到 newman 或插件:确认已全局安装并在 PATH 中可用(which newman)。
    • 报告中文或样式异常:优先使用 htmlextra 报告;若在 Jenkins 展示 HTML 报告,注意其默认 CSP 限制,可临时在“脚本命令行”执行:System.setProperty(“hudson.model.DirectoryBrowserSupport.CSP”, “”)。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: centos中postman如何导出报告
本文地址: https://pptw.com/jishu/765250.html
centos上postman如何进行接口测试 centos下postman如何使用Runner

游客 回复需填写必要信息