Postman (Manual + Design Phase)
Used by DevOps to:
- Test APIs before deployment
- Validate endpoints (GET, POST, DELETE)
- Work with developers (API contract testing)
- Save collections for automation
Newman (Automation Phase)
CLI tool to:
- Run Postman collections in CI/CD
- Validate APIs after deployment
- Block bad releases automatically
π Key Idea:
- Postman = Manual testing
- Newman = Automated testing in pipeline
π₯ 2. WHAT TESTS DEVOPS ENGINEERS DO
1. Health Check Test
GET /health
Check:
- API is alive
- Returns 200
2. Functional Test
POST /users
Check:
- Response contains correct data
- Fields match expected
3. Status Code Validation
pm.test("Status is 200", function () {
pm.response.to.have.status(200);
});
4. Response Body Validation
pm.test("User created", function () {
let json = pm.response.json();
pm.expect(json.name).to.eql("Aisalkyn DevOps");
});
5. Performance Check (Basic)
pm.test("Response time < 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
6. Schema Validation (Advanced DevOps)
Validate structure:
pm.test("Response has id", function () {
let json = pm.response.json();
pm.expect(json).to.have.property("id");
});
7. Negative Testing
POST /users (invalid body)
Check:
- API rejects bad input
- Returns 400
π₯ 3. LAB β COMPLETE STRUCTURE (REAL DEVOPS)
π Project Structure
postman-newman-lab/
βββ .github/
β βββ workflows/
β βββ api-test.yml
βββ collection.json
βββ environment.json
βββ README.md
π₯ 4. STEP-BY-STEP LAB
β Step 1 β Create Postman Collection
Use API:
https://reqres.in/api/users
POST Request
Body:
{
"name": "Aisalkyn DevOps",
"job": "Cloud Engineer"
}
β Step 2 β Add Tests in Postman
Go to Tests tab:
pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Response has name", function () {
let json = pm.response.json();
pm.expect(json.name).to.eql("Aisalkyn DevOps");
});
β Step 3 β Create Environment
base_url = https://reqres.in/api
β Step 4 β Export Files
Export:
- Collection β
collection.json - Environment β
environment.json
β Step 5 β Install Newman
npm install -g newman
Run locally:
newman run collection.json -e environment.json
π₯ 5. GITHUB ACTIONS (REAL PIPELINE)
.github/workflows/api-test.yml
name: API Tests
on:
push:
branches:
- main
jobs:
test-api:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Newman
run: npm install -g newman
- name: Run API Tests
run: newman run collection.json -e environment.json
π₯ 6. WHY IT WORKS IN POSTMAN BUT FAILS IN GITHUB ACTIONS
β 1. Missing Environment Variables
Postman has:
{{base_url}}
GitHub β doesn't know it
π Fix:
- Ensure
environment.jsonis included
β 2. Hardcoded Localhost
Works locally:
http://localhost:3000
Fails in CI because:
- No local server running
β 3. Authentication Missing
Postman:
- Uses saved token
GitHub:
- No token
β 4. Collection Uses Variables Not Defined
Example:
{{user_id}}
β 5. Network Restrictions / API Down
π₯ 7. WHY WE PUSH TO GITHUB
We push because:
1. CI/CD Automation
- Every push β API tested automatically
2. Prevent Broken Deployments
- If tests fail β pipeline fails
3. Team Collaboration
- Everyone uses same tests
4. Version Control
- Track API changes
π₯ 8. WHAT OUTPUT WE GIVE TO MANAGER
Example Report:
API Test Report
- Total Requests: 10
- Passed: 9
- Failed: 1
- Success Rate: 90%
- Avg Response Time: 320ms
Failed Endpoint:
POST /users β 500 error
Newman Report Command (Advanced)
newman run collection.json \
-e environment.json \
-r cli,html \
--reporter-html-export report.html
π You send:
- HTML report
- Logs
- Pipeline status
π₯ 9. REAL DEVOPS SCENARIO
Pipeline flow:
Developer pushes code
β
Build (Docker)
β
Deploy (ECS / Kubernetes)
β
Run Newman Tests
β
IF FAIL β rollback
IF PASS β release
π₯ 10. WHAT INTERVIEWERS EXPECT
You should say:
- "We use Postman for API validation and Newman in CI/CD pipelines"
- "We validate status codes, response body, schema, and performance"
- "Newman helps prevent bad deployments"
- "Failures in CI usually happen due to missing env variables or auth"
Top comments (0)