Skip to main content

API Testing with Postman & Newman: Beyond Clicks and Collections

API Testing with Postman & Newman: Beyond Clicks and Collections

API Testing with Postman & Newman: Beyond Clicks and Collections

Intro — You’ve clicked “Send” in Postman hundreds of times — but real API testing is more than watching a 200 OK appear. It’s about trusting data integrity, contracts, and behavior under edge cases. Today we go beyond clicks — into automation, validation and continuous confidence.

1️⃣ What is API Testing Really About?

API testing is validating the communication between services. Instead of a UI, you test requests and responses directly — faster, more reliable, and perfect for early feedback.

Typical objectives:

  • Confirm status codes and headers
  • Validate response data structure and types
  • Check business rules and edge cases
  • Measure response times and error handling
Think of API testing as the X-ray of your application — you see what’s under the UI skin.

2️⃣ Setting Up Postman — from Collections to Environments

Start with a simple example API: https://reqres.in/api/users

  1. Create a collection “User API Tests”
  2. Add GET / POST requests with params and headers
  3. Use Environments to store base URL and token variables (e.g., {{base_url}})
  4. Add scripts under “Tests” tab to assert responses

Example Test Script in Postman


// Tests tab in Postman

pm.test("Status code is 200", function () {

  pm.response.to.have.status(200);

});

pm.test("User object contains email", function () {

  var json = pm.response.json();

  pm.expect(json.data.email).to.include("@");

});

3️⃣ Running Collections with Newman

Newman is Postman’s command-line runner — perfect for CI. Install it with:

npm install -g newman

Export your Postman collection and environment files (.json), then run:

newman run User_API_Tests.postman_collection.json -e QAEnv.postman_environment.json --reporters cli,html
Mentor tip: Treat your Postman collection like code — version it, review it, and run it every build.

4️⃣ Validating JSON Responses — Deep Checks


// Example in Postman

pm.test("JSON schema is valid", function () {

  const schema = {

    "type":"object",

    "properties":{

      "data":{"type":"object"},

      "support":{"type":"object"}

    },

    "required":["data","support"]

  };

  pm.expect(tv4.validate(pm.response.json(), schema)).to.be.true;

});

You can use libraries like Ajv or tv4 for schema validation. Postman already bundles tv4.

5️⃣ Real Example — Login and Token Flow

Let’s simulate an API login and subsequent authorized call.


// POST /login

pm.test("Token is returned", function () {

  let data = pm.response.json();

  pm.expect(data.token).to.be.a("string");

  pm.environment.set("token", data.token);

});

// GET /users (after login)

pm.request.headers.add({

  key: "Authorization",

  value: "Bearer " + pm.environment.get("token")

});

Now your API tests are linked — mimicking real user journeys across requests.

6️⃣ Python Validation Alternative

If you love Python, you can run simple API validations using requests + pytest for cross-checking your Postman logic.


import requests, pytest

def test_users_list():

  r = requests.get("https://reqres.in/api/users?page=2")

  assert r.status_code == 200

  data = r.json()

  assert "data" in data

  assert data["data"][0]["email"].endswith("@reqres.in")

7️⃣ Integrating Newman with CI/CD

Here’s a GitHub Actions workflow that runs Postman tests on each PR:


name: API Tests

on: [pull_request]

jobs:

  newman:

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v3

      - name: Install Newman

        run: npm install -g newman

      - name: Run API Tests

        run: |

          newman run postman/User_API_Tests.json -e postman/QAEnv.json --reporters cli,junit

      - name: Upload Results

        if: failure()

        uses: actions/upload-artifact@v3

        with:

          name: newman-reports

          path: newman/

8️⃣ Common Mistakes & Fixes

MistakeBetter Approach
Hardcoding URLs or tokensUse environment variables
Ignoring response timeAdd pm.expect(pm.response.responseTime < 500)
One giant collection fileModularize by feature or service
Manual runs onlyAutomate with Newman + CI

9️⃣ Performance Quick Checks

Postman can measure latency too:

pm.test("Response time < 500ms", function () {

  pm.expect(pm.response.responseTime).to.be.below(500);

});
Mini Challenge (30 min):
  1. Create a Postman collection for GET/POST / DELETE users
  2. Add auth token flow between requests
  3. Run it with Newman and generate an HTML report
  4. Bonus: Integrate it in a GitHub Action

🔟 How to Evolve API Testing in Your Team

  • Start simple: a few core endpoints with auth flow
  • Automate daily: run collections nightly in CI
  • Add schema validation: prevent breaking changes
  • Visualize trends: track failure rates and response times

Final Thought — The API Mindset

APIs connect everything — your UI, mobile apps, and third-party integrations. A QA engineer who understands and tests APIs is already halfway to becoming an SDET. The tools (Postman, Newman) are just means — the real skill is how you think about data, contracts, and impact.

Comments

Popular posts from this blog

Playwright frameLocator() Guide (2026): Automate Frames & iFrames Like a Pro

Playwright Frames & iFrames Explained: frameLocator(), Nested Frames & Best Practices (2026) Reading Time: 20–25 Minutes Level: Beginner to Advanced Category: Playwright Tutorial If you've ever written a Playwright test that couldn't find a button even though it was clearly visible on the page, there's a good chance you were dealing with an iframe . Frames are one of the most misunderstood topics in browser automation. Many beginners spend hours debugging perfectly valid locators before realizing the element is actually inside another browsing context. Modern web applications heavily rely on iframes for payment gateways, customer support widgets, embedded dashboards, videos, advertisements, maps, authentication pages, and third-party integrations. Fortunately, Playwright makes working with frames much easier than traditional automation frameworks through its powerful frameLocator() API. In this complete guide, you'll learn how frames w...

Selenium 5: What’s New and Why It Still Matters in 2025

Selenium 5: What’s New and Why It Still Matters in 2025 data-full-width-responsive="true"> Selenium has been the backbone of web automation testing for over a decade. From the early days of Selenium RC to WebDriver and the release of Selenium 4, it has enabled QA engineers worldwide to automate browsers reliably. But as modern frameworks like Playwright and Cypress gained attention, critics started asking: “Is Selenium dead?” In 2025, the answer is clear: Selenium is not dead — it has evolved. With the release of Selenium 5 , the project has modernized to support new browser technologies, improve stability, and remain a cornerstone of test automation strategies. 1. Introduction — Selenium’s Legacy Selenium started in 2004 as a tool to automate browsers for functional testing. Over the years: Selenium RC gave way to Selenium WebDriver. Selenium Grid enabled parallel execution at scale. Selenium 4 introduced W3C WebDriver com...

Playwright Actions Guide (2026): Click, Fill, Hover, Drag & Drop, Upload Files & More

Playwright Actions Explained: Click(), Fill(), Hover(), Drag & Drop, Upload Files & More (2026) Reading Time: 20 Minutes Level: Beginner to Advanced Category: Playwright Tutorial Every automation script performs one simple sequence: Locate Element ↓ Perform Action ↓ Validate Result You already learned how to locate elements using Playwright Locators and how to verify them using Assertions. Now it's time to understand the most important part of automation—performing user actions. Whether you're automating a login page, testing an e-commerce checkout, uploading files, selecting dropdown values, dragging Kanban cards, or filling complex forms, you'll use Playwright Actions in almost every test case. In this guide you'll learn every important Playwright Action with practical examples, interview questions, certification notes, and enterprise best practices. Table of Contents What are Playwright Actions? Why ...