API TESTING
AUTOMATION
USING
ER. MANISH KHADKA
TABLE OF CONTENTS
1. Chapter 1: Introduction to API Testing
2. Chapter 2: Understanding Postman - The Tool of
Choice
3. Chapter 3: Creating and Sending API Requests
4. Chapter 4: Writing and Validating API Tests in
Postman
5. Chapter 5: Automating API Tests with Collection
Runner
6. Chapter 6: Environment and Variable
Management in Postman
7. Chapter 7: Integrating Postman with CI/CD
Pipelines
8. Chapter 8: Real-world Project Examples
9. Chapter 9: Common Pitfalls and Best Practices
10. Chapter 10: Final Thoughts and Career Advice
Chapter 1: Introduction to API Testing
APIs (Application Programming Interfaces) are the
backbone of modern software systems. They allow different
systems and components to communicate. As a QA
engineer, testing these APIs ensures data integrity,
reliability, and proper functionality.
Why API Testing Matters:
Verifies business logic
Checks response correctness and performance
Helps in early defect detection
Can be integrated into automation suites
Chapter 2: Understanding Postman -
The Tool of Choice
Postman is a user-friendly and powerful tool for testing
APIs. It simplifies the process of developing, sending, and
automating requests.
Postman Features:
REST, SOAP, and GraphQL support
JavaScript-based test scripting
Collection Runner for test automation
Environment and global variable handling
Integration with CI/CD tools via Newman
Installing Postman: Visit https://www.postman.com and
download the desktop application.
Chapter 3: Creating and Sending API
Requests
Learn the core functions of Postman to make API requests
and understand HTTP communication.
Steps to Create a Request:
1.Open Postman and create a new request tab
2.Select method (GET, POST, PUT, DELETE, etc.)
3.Enter the API endpoint URL
4.Set request headers
5.Provide body payload (for POST/PUT)
6.Click "Send" and inspect the response
Understanding Response Sections:
Status Code: e.g., 200 OK, 404 Not Found
Headers: metadata about the response
Body: actual content/data returned by the API
Time & Size: performance indicators
Chapter 4: Writing and Validating API
Tests in Postman
Postman allows test script creation using JavaScript to
verify the correctness of the response.
Basic Test Example:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
More Advanced Assertions:
pm.test("Content-Type is JSON", function () {
pm.response.to.have.header("Content-Type",
/application\/json/);
});
pm.test("User ID is present", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.id).to.exist;
});
Using Test Results:
Pass/fail statuses visible under "Test Results"
Helps create reliable, automated regression suites
Chapter 5: Automating API Tests with
Collection Runner
Postman’s Collection Runner allows you to execute a
group of requests with tests automatically.
Steps to Use Collection Runner:
1.Group requests into a Collection
2.Open the Collection Runner
3.Select environment (if needed)
4.Set number of iterations, delay, and data file
(CSV/JSON)
5.Run the collection and monitor results
Advantages:
Batch execution
Useful for smoke and regression testing
Combine with data files for parameterized testing
Chapter 6: Environment and Variable
Management in Postman
Variables make requests reusable and flexible.
Types of Variables:
Global: available across all requests
Environment: scoped to specific environments
Collection: scoped to the collection
Local: temporary for one execution
Using Variables:
{{baseUrl}}/api/users
Best Practices:
Store tokens, base URLs, and dynamic values
Use pre-request scripts to update variables
Chapter 7: Integrating Postman with
CI/CD Pipelines
Newman is Postman’s CLI that allows collection execution
from command line or CI servers.
Installing Newman:
npm install -g newman
Basic Command:
newman run collection.json -e environment.json
Use Cases:
Automate tests in Jenkins, GitHub Actions, or Azure
DevOps
Get test summaries in CI pipeline logs
Chapter 8: Real-world Project
Examples
Example 1: Login API
Validate correct token generation
Handle incorrect credentials
Example 2: User Registration API
Schema validation
Duplicate checks
Example 3: Transaction API
Handle boundary values
Time-based performance testing
Chapter 9: Common Pitfalls and Best
Practices
Pitfalls to Avoid:
Hardcoding values in tests
Ignoring negative scenarios
Not handling authentication tokens dynamically
Best Practices:
Modularize requests into folders
Use descriptive test names
Store reusable code in variables/scripts
Document each endpoint
Chapter 10: Final Thoughts and Career
Advice
API Testing is a vital skill for modern QA professionals. Tools
like Postman offer a smooth learning curve yet powerful
capabilities.
Career Tips for Junior QAs and Students:
Build mini projects using public APIs
Learn JavaScript basics for scripting
Contribute to open-source test suites
Create a portfolio on GitHub with Postman collections
Stay updated with Postman features and API trends