SiamCafe · Blog
Postman Newman Remote Work Setup — ทดสอบ API
บทความ

Postman Newman Remote Work Setup — ทดสอบ API

เผยแพร่ 28 พฤษภาคม 2569

Postman Newman Remote Work

Postman Newman Remote Work Setup — ทดสอบ API

Postman Newman Remote Work API Testing Cloud Workspace Team Collaboration CI/CD Monitor Schedule Distributed Testing

FeatureFreeBasic ($14/user)Professional ($29/user)Enterprise
WorkspacesPersonal onlyTeam WorkspaceTeam + PrivateAll + SSO
Collection Runs25/month250/monthUnlimitedUnlimited
Monitor Calls1000/month10000/month100000/monthCustom
Mock Servers1000 calls10000 calls100000 callsCustom
Version ControlBasicFork + PRFork + PR + ApproveFull audit
IntegrationsLimitedCI/CD + SlackAll + CustomAll + SCIM

Workspace and Collaboration

# === Team Workspace Setup ===

# 1. Create Team Workspace
# Postman > Workspaces > Create Workspace
#   Name: "API Testing - Team Alpha"
#   Type: Team
#   Visibility: Team
#   Invite: team@company.com

# 2. Organize Collections
# Workspace/
# ├── Auth API Tests/
# │   ├── Login
# │   ├── Register
# │   └── Token Refresh
# ├── User API Tests/
# │   ├── CRUD Operations
# │   └── Profile Management
# ├── Payment API Tests/
# │   ├── Create Payment
# │   └── Webhook Validation
# └── Environments/
#     ├── dev.postman_environment.json
#     ├── staging.postman_environment.json
#     └── prod.postman_environment.json

# 3. Postman API — Fetch Collection programmatically
# curl -X GET "https://api.getpostman.com/collections/{{collection_uid}}" \
#   -H "X-Api-Key: {{postman_api_key}}"

from dataclasses import dataclass

@dataclass
class WorkflowStep:
    step: str
    actor: str
    action: str
    tool: str

workflow = [
    WorkflowStep("1. Design", "API Designer",
        "Create API spec in Postman, define endpoints",
        "Postman API Builder"),
    WorkflowStep("2. Mock", "Frontend Dev",
        "Use Mock Server to develop against API before backend ready",
        "Postman Mock Server"),
    WorkflowStep("3. Implement", "Backend Dev",
        "Implement API, run Collection tests locally",
        "Postman Desktop + Newman"),
    WorkflowStep("4. Test", "QA Engineer",
        "Fork Collection, add test cases, Pull Request back",
        "Postman Fork + PR"),
    WorkflowStep("5. Review", "Tech Lead",
        "Review PR, check test coverage, approve merge",
        "Postman PR Review"),
    WorkflowStep("6. CI/CD", "DevOps",
        "Newman runs tests in pipeline after deploy",
        "Newman + GitHub Actions"),
    WorkflowStep("7. Monitor", "SRE/DevOps",
        "Schedule Monitor for production health checks",
        "Postman Monitor"),
]

print("=== Remote API Workflow ===")
for w in workflow:
    print(f"  {w.step}: [{w.actor}] {w.action}")
    print(f"    Tool: {w.tool}")

Newman CI/CD Pipeline

Postman Newman Remote Work Setup — ทดสอบ API
# === Newman in CI/CD ===

# GitHub Actions
# name: API Tests
# on: [push, pull_request]
# jobs:
#   api-test:
#     runs-on: ubuntu-latest
#     steps:
#       - uses: actions/checkout@v4
#       - uses: actions/setup-node@v4
#         with: { node-version: '20' }
#       - run: npm install -g newman newman-reporter-htmlextra
#       - name: Run API Tests (Dev)
#         run: |
#           newman run tests/collection.json \
#             -e tests/env/dev.json \
#             --reporters cli, junit, htmlextra \
#             --reporter-junit-export results/junit.xml \
#             --reporter-htmlextra-export results/report.html \
#             --delay-request 100
#       - uses: actions/upload-artifact@v4
#         if: always()
#         with:
#           name: api-test-results
#           path: results/

# Docker-based Newman
# docker run -v $(pwd)/tests:/etc/newman \
#   postman/newman run collection.json \
#   -e env/staging.json \
#   --reporters cli, junit

# Postman API — Run latest Collection from cloud
# newman run "https://api.getpostman.com/collections/{{uid}}?apikey={{key}}" \
#   -e "https://api.getpostman.com/environments/{{uid}}?apikey={{key}}"

@dataclass
class CIConfig:
    platform: str
    install: str
    run_command: str
    report: str

configs = [
    CIConfig("GitHub Actions",
        "npm install -g newman newman-reporter-htmlextra",
        "newman run collection.json -e env.json --reporters cli, junit",
        "actions/upload-artifact for HTML/JUnit"),
    CIConfig("GitLab CI",
        "npm install -g newman (in before_script)",
        "newman run collection.json -e env.json --bail",
        "artifacts: paths: [results/]"),
    CIConfig("Jenkins",
        "npm install -g newman (in Build step)",
        "newman run collection.json -e env.json",
        "JUnit plugin for test results"),
    CIConfig("Docker",
        "docker pull postman/newman",
        "docker run -v ./tests:/etc/newman postman/newman run collection.json",
        "Mount results volume"),
]

print("\n=== CI/CD Configurations ===")
for c in configs:
    print(f"  [{c.platform}]")
    print(f"    Install: {c.install}")
    print(f"    Run: {c.run_command}")
    print(f"    Report: {c.report}")

Monitoring and Alerts

# === Production Monitoring ===

@dataclass
class MonitorConfig:
    name: str
    collection: str
    schedule: str
    region: str
    alert: str
    sla: str

monitors = [
    MonitorConfig("Health Check", "Smoke Tests",
        "Every 5 minutes", "US East + Asia Pacific",
        "Slack #ops-alerts + PagerDuty", "99.9% uptime"),
    MonitorConfig("API Contract", "Contract Tests",
        "Every hour", "US East",
        "Slack #api-team", "No schema changes"),
    MonitorConfig("Performance", "Perf Tests",
        "Every 30 minutes", "US East + EU West + Asia",
        "Email + Slack if p95 > 2s", "p95 < 2s"),
    MonitorConfig("Auth Flow", "Auth E2E Tests",
        "Every 15 minutes", "US East",
        "PagerDuty critical", "100% success rate"),
    MonitorConfig("Integration", "Full Integration",
        "Daily at 02:00 UTC", "US East",
        "Email summary to team", "95% pass rate"),
]

print("=== Monitor Configurations ===")
for m in monitors:
    print(f"  [{m.name}] Collection: {m.collection}")
    print(f"    Schedule: {m.schedule} | Region: {m.region}")
    print(f"    Alert: {m.alert} | SLA: {m.sla}")

# Best practices for remote teams
practices = {
    "Single Source of Truth": "ใช้ Team Workspace เป็นที่เดียวสำหรับ Collection",
    "Environment Separation": "แยก Environment ไฟล์ ไม่ Hardcode URL/Token",
    "Fork Workflow": "Fork แก้ไข PR Review ไม่แก้ Main Collection ตรง",
    "Automated Testing": "ทุก PR ต้องผ่าน Newman Test ก่อน Merge",
    "Documentation": "ใช้ Postman Documentation สร้าง API Doc อัตโนมัติ",
    "Secrets Management": "ใช้ Postman Vault หรือ CI Secrets ไม่เก็บ Token ใน Collection",
}

print(f"\n\nBest Practices:")
for k, v in practices.items():
    print(f"  [{k}]: {v}")

เคล็ดลับ

  • Workspace: ใช้ Team Workspace แชร์ Collection ไม่ต้องส่งไฟล์กัน
  • Fork: Fork Collection ก่อนแก้ไข แล้ว PR กลับ เหมือน Git
  • Newman: รัน Newman ใน CI/CD ทุก Deploy ตรวจ API อัตโนมัติ
  • Monitor: ตั้ง Monitor สำหรับ Production Health Check ทุก 5 นาที
  • Secrets: อย่าเก็บ API Key ใน Collection ใช้ Environment Variables

Postman Remote Work Setup คืออะไร

Cloud Workspace Collection Environment Team Library Version Control Comment Fork Pull Request Monitor Newman CI/CD Schedule