Skip to content

Repository files navigation

Postman Newman API Testing

Tests Newman Postman JavaScript

Professional API testing framework using Postman collections and Newman CLI automation for the JSONPlaceholder REST API.


🎯 Project Purpose

This project demonstrates:

  • Professional API testing with Postman
  • Multi-environment testing (Dev, QA, Staging)
  • CLI automation with Newman
  • HTML reporting with newman-reporter-htmlextra
  • Organized test suites with clear structure
  • CI/CD ready architecture

This is NOT just running Postman tests.
This IS a complete testing framework for API validation.


🗂️ Project Structure

postman-newman-api-testing/
├── collections/
│   └── JSONPlaceholder_API_Tests.postman_collection.json
├── environments/
│   ├── JSONPlaceholder-Dev.postman_environment.json
│   ├── JSONPlaceholder-QA.postman_environment.json
│   └── JSONPlaceholder-Staging.postman_environment.json
├── reports/                        # Generated HTML reports
├── docs/                           # Documentation
├── .gitignore
├── package.json
└── README.md

🧪 Test Coverage

API Under Test: JSONPlaceholder

Test Suite Requests Assertions Status
1. GET Operations 2 12
2. POST Operations 1 5
3. PUT/PATCH Operations 1 5
4. DELETE Operations 1 3
5. Negative Tests 3 7
Total 8 requests 32 assertions 100%

Test Scenarios:

Positive Tests:

  • ✅ Get all posts
  • ✅ Get single post by ID
  • ✅ Create new post
  • ✅ Update existing post
  • ✅ Delete post
  • ✅ Response time validation (< 2000ms)

Negative Tests:

  • ❌ 404 - Post not found
  • ❌ Missing required fields
  • ❌ Invalid data handling

🚀 Getting Started

Prerequisites

  • Node.js v14+
  • Postman (for GUI testing)
  • Newman CLI (installed via npm)

Installation

  1. Clone the repository:
   git clone https://github.com/your-username/postman-newman-api-testing.git
   cd postman-newman-api-testing
  1. Install dependencies:
   npm install
  1. Verify installation:
   npx newman --version
   # Should show: newman/6.x.x

▶️ Running Tests

The project uses cross-platform NPM scripts to run the tests.

Run Tests by Environment (with HTML reporting)

npm run test:dev
npm run test:qa
npm run test:staging

This will run the full test suite in the specified environment and automatically generate an HTML report in the reports/ folder.


Run All Environments Sequentially

npm run test:all

Run Smoke Tests (Quick Validation)

npm run test:smoke

Runs only the GET Operations folder for quick validation.


Command Line (Manual via NPX)

Basic run:

npx newman run collections/JSONPlaceholder_API_Tests.postman_collection.json \
  -e environments/JSONPlaceholder-Dev.postman_environment.json

🌍 Environments

Development

  • Base URL: https://jsonplaceholder.typicode.com
  • Purpose: Local development testing
  • Variables: base_url, post_id, environment

QA

  • Base URL: https://jsonplaceholder.typicode.com
  • Purpose: QA environment validation
  • Variables: base_url, post_id, environment

Staging

  • Base URL: https://jsonplaceholder.typicode.com
  • Purpose: Pre-production testing
  • Variables: base_url, post_id, environment, timeout

Note: In a real project, each environment would have different URLs.


📊 Test Results

Console Output:

┌─────────────────────────┬───────────────────┬───────────────────┐
│                         │          executed │            failed │
├─────────────────────────┼───────────────────┼───────────────────┤
│              iterations │                 1 │                 0 │
├─────────────────────────┼───────────────────┼───────────────────┤
│                requests │                 8 │                 0 │
├─────────────────────────┼───────────────────┼───────────────────┤
│              assertions │                32 │                 0 │
└─────────────────────────┴───────────────────┴───────────────────┘

HTML Report:

Open reports/[env]-report-[timestamp].html in browser for:

  • ✅ Visual test results dashboard
  • ✅ Request/response details
  • ✅ Execution timeline
  • ✅ Performance metrics
  • ✅ Pass/fail statistics

🧩 Collection Organization

Tests are organized in numbered folders for sequential execution:

1. POST - GET/
   ├── Get all Requests       # Lists all posts
   └── Get Single Post        # Retrieves post by ID

2. Posts - POST/
   └── Create New Post        # Creates a new post

3. Posts - PUT/PATCH/
   └── Update Post (PUT)      # Updates existing post

4. Posts - DELETE/
   └── Delete Post            # Deletes a post

5. Negative Tests/
   ├── Get Post - Not Found   # 404 handling
   ├── Create Post - Missing Body  # Validation
   └── Delete Post - Not Found     # Error handling

🔍 Test Scripts (JavaScript)

Example: Status Code Validation

pm.test("Status code is 200", function () {
  pm.response.to.have.status(200);
});

Example: Response Time

pm.test("Response time is less than 2000ms", function () {
  pm.expect(pm.response.responseTime).to.be.below(2000);
});

Example: Data Structure Validation

pm.test("Response is an array", function () {
  const jsonData = pm.response.json();
  pm.expect(jsonData).to.be.an("array");
});

pm.test("Post has correct structure", function () {
  const post = pm.response.json()[0];
  pm.expect(post).to.have.property("userId");
  pm.expect(post).to.have.property("id");
  pm.expect(post).to.have.property("title");
  pm.expect(post).to.have.property("body");
});

🎓 Learning Outcomes

Skills Demonstrated:

API Testing:

  • RESTful API validation
  • HTTP methods (GET, POST, PUT, DELETE)
  • Status code verification
  • Response validation
  • Error handling

Automation:

  • Newman CLI usage
  • Environment management
  • Batch scripting
  • Report generation

Quality Assurance:

  • Test organization
  • Positive/negative testing
  • Regression testing
  • Multi-environment validation

🔧 Customization

Adding New Tests:

  1. Open collection in Postman
  2. Add new request to appropriate folder
  3. Write test scripts in "Tests" tab
  4. Export collection (v2.1)
  5. Replace collections/JSONPlaceholder_API_Tests.postman_collection.json

Adding New Environment:

  1. Create environment in Postman
  2. Add required variables (base_url, etc.)
  3. Export environment
  4. Save to environments/ folder
  5. Update scripts to include new environment

📚 Documentation


🚧 Future Improvements

  • Add data-driven testing with CSV/JSON
  • Implement CI/CD with GitHub Actions
  • Add performance testing scenarios
  • Create custom Newman reporter
  • Add authentication testing (OAuth, JWT)
  • Integrate with test management tools

👤 Chande De Vargas


📄 License

This project is open source and available under the MIT License.


⭐ If this project helped you learn Postman and Newman, give it a star!

About

Professional API testing framework demonstrating Postman automation, Newman CLI integration, JavaScript test scripting, and comprehensive test coverage with visual HTML reports.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages