Skip to content

ChandeDeVargas/postman-newman-api-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages