Skip to content

Repository files navigation

📚 Library API — Postman Collection

Postman API Tests

A Postman collection for end-to-end testing of a Library REST API. It covers the full lifecycle of a book record — adding, retrieving, and deleting — with automated test assertions at every step.


📋 Table of Contents

  1. Collection Overview
  2. Prerequisites & Setup
  3. Execution Workflow
  4. Requests
  5. Variables
  6. How to Run
  7. Test Coverage Summary
  8. Notes

Collection Overview

Property Value
Collection Name Library
Base URL {{base_url}} (e.g. http://216.10.245.166)
Total Requests 3
Total Tests 15 assertions
Environment QA
Execution Order Sequential (AddBook → GetBook → DeleteBook)

Prerequisites & Setup

  1. Import the collection into Postman.
  2. Import the QA environment and set it as the active environment.
  3. Set the Global variable CompanyCode to your desired prefix (default: RS).
  4. Ensure the Library API server is reachable at the base_url.

Execution Workflow

The requests are designed to run sequentially in this order:

AddBook  ──►  GetBook  ──►  DeleteBook
   │               │               │
   │  Sets         │  Validates     │  Deletes
   │  book_id  ────┘  book data     │  by book_id
   └──────────────────────────────►┘
  • AddBook creates a new book and saves the returned ID to the book_id environment variable.
  • GetBook uses book_id to fetch and validate the book details.
  • DeleteBook uses book_id to delete the book and confirms deletion.

Requests

1. AddBook

Property Value
Method POST
URL {{base_url}}/Library/Addbook.php

Request Body (JSON):

{
  "name": "Learn Appium Automation with Java",
  "isbn": "{{isbn}}",
  "aisle": "2278899",
  "author": "{{author_name}}"
}

Pre-Request Script:

  • Reads CompanyCode from global variables (e.g. RS).
  • Generates a random integer using {{$randomInt}}.
  • Concatenates them to form a unique isbn (e.g. RS4821) and sets it as a collection variable.
  • Sets author_name collection variable to "Rahul Shetty".
const code = pm.globals.get("CompanyCode");
const val = pm.variables.replaceIn('{{$randomInt}}');
pm.collectionVariables.set("isbn", code + val);
pm.collectionVariables.set("author_name", "Rahul Shetty");

Test Assertions:

  • ✅ Status code is 200
  • ✅ Response message is "successfully added"
  • ✅ Returned ID includes the isbn value
  • ✅ Content-Type header is application/json;charset=UTF-8
  • ✅ Response time is below 2000ms
  • ✅ ID concatenation logic: isbn + aisle === returned ID
  • ✅ Saves returned ID to environment variable book_id

2. GetBook

Property Value
Method GET
URL {{base_url}}/Library/GetBook.php
Query Param ID = {{book_id}}

Test Assertions:

  • ✅ Status code is 200
  • ✅ Response matches JSON schema (array of objects with book_name, isbn, aisle, author)
  • ✅ author matches collection variable author_name
  • ✅ isbn matches collection variable isbn
  • ✅ book_name is "Learn Appium Automation with Java"
  • ✅ aisle is "2278899"

JSON Schema Validated:

{
  "type": "array",
  "items": {
    "type": "object",
    "required": ["book_name", "isbn", "aisle", "author"],
    "properties": {
      "book_name": { "type": "string" },
      "isbn":      { "type": "string" },
      "aisle":     { "type": "string" },
      "author":    { "type": "string" }
    }
  }
}

3. DeleteBook

Property Value
Method POST
URL {{base_url}}/Library/DeleteBook.php

Request Body (JSON):

{
  "ID": "{{book_id}}"
}

Test Assertions:

  • ✅ Status code is 200
  • ✅ Response message is "book is successfully deleted"

Variables

Environment Variables (QA)

Set these in the QA environment before running the collection.

Variable Example Value Description
base_url http://216.10.245.166 Base URL of the Library API server
book_id RS4822278899 Book ID returned by AddBook; automatically set by the AddBook post-response script. Used by GetBook and DeleteBook.
url http://216.10.245.166 Alternate URL variable (same as base_url)

Global Variables

These are workspace-wide variables shared across all collections.

Variable Example Value Description
CompanyCode RS Prefix used to generate the isbn. Prepended to a random integer (e.g. RS + 4821 = RS4821).
access_token <token> OAuth access token used for authenticated requests in other collections.

Collection Variables

These are set dynamically at runtime by the pre-request script of AddBook.

Variable Set By Example Value Description
isbn AddBook pre-request RS4821 Generated as CompanyCode + random integer. Used in the request body and validated in tests.
author_name AddBook pre-request Rahul Shetty Author name used in the request body and validated in GetBook tests.

How to Run

Option 1: Postman Collection Runner

  1. Open the Library collection in Postman.
  2. Click Run collection.
  3. Select the QA environment.
  4. Ensure the request order is: AddBook → GetBook → DeleteBook.
  5. Click Run Library.

Option 2: Newman CLI

# Install Newman
npm install -g newman

# Run the collection
newman run Library.postman_collection.json \
  --environment QA.postman_environment.json \
  --globals globals.json

Test Coverage Summary

Request Assertions What's Validated
AddBook 7 Status code, response message, ID format, Content-Type header, response time, ID concatenation logic, book_id saved to env
GetBook 6 Status code, JSON schema, author, isbn, book_name, aisle
DeleteBook 2 Status code, deletion confirmation message
Total 15

Notes

  • 🔗 Sequential execution is required. AddBook must run before GetBook and DeleteBook, as book_id is set dynamically.
  • 🎲 Dynamic ISBN generation ensures each test run uses a unique book, preventing conflicts.
  • 🔄 Variable chaining: CompanyCode (global) → isbn (collection) → book_id (environment) flows across all three requests automatically.
  • 📊 Data-driven testing is supported. The pre-request script has commented-out lines to read BookName and Author from iteration data files for bulk testing via the Collection Runner.
  • 🌍 Environment isolation: Using the QA environment keeps test data separate from other environments.

About

Postman mini Library Management Project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors