跳到正文
Skillpedia
部署与云(DevOps)48k · #5477

postman-newman-automation

它能做什么

这个工具可以生成命令和脚本,用来自动运行 API 测试。它能帮你在开发环境中,或在 Jenkins 等 CI/CD 系统里,执行 Postman 测试集合。

适用场景

  • ✓当你需要在图形界面之外运行 Postman API 测试时。
  • ✓当你想在 CI/CD 流水线中自动执行 API 测试时。
  • ✓想生成 HTML 或 XML 等格式的 API 测试报告时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postman-newman-automation/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/postman-newman-automation/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“帮我写一条命令,用 'prod.json' 环境运行我的 'api_tests.json' 集合,生成名为 'report.html' 的 HTML 报告,并且在有测试失败时停止运行。”

每周 5 个新技能,1 分钟读完。

工作原理

这个工具基于 Newman,它是 Postman 的命令行程序。工具会拼出所需的命令,包括指定集合文件、环境文件和报告类型的选项。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Postman Newman Automation

When to Use

Use this skill when you need generate Newman CLI commands, configuration files, Jenkins pipeline scripts, and shell automation for running Postman collections in CI/CD or local environments. Use this skill whenever the user wants to run Postman collections from the command line, automate API tests, integrate...

Generates Newman CLI commands, shell scripts, and Jenkins pipeline configs for running Postman collections in automated environments.


Newman Basics

Newman is Postman's CLI runner. Install with:

npm install -g newman
# Optional HTML reporter:
npm install -g newman-reporter-htmlextra

Core Command Structure

newman run <collection> \
  --environment <env-file> \
  --globals <globals-file> \
  --iteration-count <n> \
  --iteration-data <csv-or-json> \
  --reporters <reporter-list> \
  --reporter-htmlextra-export <output.html> \
  --reporter-junit-export <results.xml> \
  --timeout-request <ms> \
  --delay-request <ms> \
  --bail \
  --color on

Step 1 — Gather Requirements

Ask or infer from context:

Parameter Question
Collection source File path, URL, or Postman API UID?
Environment File path or inline variables?
Reporter(s) CLI only, HTML report, JUnit XML?
Fail behavior Stop on first failure (--bail) or run all?
Iterations Single run or data-driven (CSV/JSON)?
Target Local shell, Jenkins, or both?

Step 2 — Generate Newman Command

Basic run (local)

newman run collection.json \
  --environment environment.json \
  --reporters cli,htmlextra \
  --reporter-htmlextra-export reports/report.html \
  --bail

Run from Postman API (by UID)

newman run "https://api.getpostman.com/collections/<UID>?apikey={{POSTMAN_API_KEY}}" \
  --environment environment.json \
  --reporters cli,junit \
  --reporter-junit-export results/junit.xml

Data-driven run (CSV)

newman run collection.json \
  --iteration-data test-data.csv \
  --iteration-count 5 \
  --reporters cli,htmlextra \
  --reporter-htmlextra-export reports/data-driven-report.html

With environment variable overrides (no file needed)

newman run collection.json \
  --env-var "base_url=https://staging.api.example.com" \
  --env-var "token=abc123" \
  --reporters cli

Step 3 — Shell Script

Generate a reusable shell script:

#!/bin/bash
set -e

# Configuration
COLLECTION="./collection.json"
ENVIRONMENT="./environment.json"
REPORT_DIR="./reports"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")

# Ensure report directory exists
mkdir -p "$REPORT_DIR"

echo "Running Newman collection: $COLLECTION"

newman run "$COLLECTION" \
  --environment "$ENVIRONMENT" \
  --reporters cli,htmlextra,junit \
  --reporter-htmlextra-export "$REPORT_DIR/report_$TIMESTAMP.html" \
  --reporter-junit-export "$REPORT_DIR/junit_$TIMESTAMP.xml" \
  --timeout-request 10000 \
  --bail

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
  echo "✅ All tests passed."
else
  echo "❌ Tests failed. Check report: $REPORT_DIR/report_$TIMESTAMP.html"
  exit $EXIT_CODE
fi

Step 4 — Jenkins Pipeline

Declarative Jenkinsfile (preferred)

pipeline {
  agent any

  environment {
    POSTMAN_ENV = credentials('postman-environment-file') // Jenkins credential ID
  }

  stages {
    stage('Install Newman') {
      steps {
        sh 'npm install -g newman newman-reporter-htmlextra'
      }
    }

    stage('Run API Tests') {
      steps {
        sh """
          newman run collection.json \\
            --environment ${POSTMAN_ENV} \\
            --reporters cli,htmlextra,junit \\
            --reporter-htmlextra-export reports/report.html \\
            --reporter-junit-export reports/junit.xml \\
            --timeout-request 10000 \\
            --bail
        """
      }
    }
  }

  post {
    always {
      // Archive HTML report
      publishHTML(target: [
        allowMissing: false,
        alwaysLinkToLastBuild: true,
        keepAll: true,
        reportDir: 'reports',
        reportFiles: 'report.html',
        reportName: 'Newman API Test Report'
      ])
      // Archive JUnit results
      junit 'reports/junit.xml'
    }
    failure {
      echo 'API tests failed! Check the Newman report.'
    }
  }
}

Scripted Jenkinsfile (if declarative not available)

node {
  stage('Install Newman') {

…
常见问题

什么是 Newman?

Newman 是 Postman 的命令行版本,让你不必打开 Postman 图形界面,直接在终端里运行 API 测试。

Postman 中的“集合”(collections)和“环境”(environments)是什么?

集合用来组织你的 API 请求和测试。环境用来存放变量(比如地址或令牌),这些变量会根据你所处的测试场景(开发、生产等)而变化。

什么是 CI/CD?

CI/CD(持续集成/持续部署)是一种软件开发实践,让测试和部署过程实现自动化。Jenkins 等工具常用于此。

详情

作者的原始描述

Generate Newman CLI commands, configuration files, Jenkins pipeline scripts, and shell automation for running Postman collections in CI/CD or local environments.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5477
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能