API Testing - PoC
SalaiGuruBalan K
Senior Software Quality Analyst., Experienced Senior Test Engineer | Driving Quality Assurance Excellence in Software Development| Manual Testing Specialist| Experienced in Test Planning, Execution, and Defect Analysis
Proof of Concept (PoC) Document for API Testing
1. Introduction
This PoC document demonstrates API testing using Postman (Manual Testing) and Python with Selenium (Automation Testing). The objective is to validate API functionality, performance, and reliability.
2. Scope
Manual API Testing: Using Postman to validate request/response behavior.
Automated API Testing: Using Python (Requests & Selenium) to automate API validation.
3. Tools & Technologies
Postman: Manual API testing
Python: Automation scripting
Selenium: Browser automation (if API response needs UI validation)
Requests Library: API interaction in Python
Pytest: Test execution framework
4. Test Environment
Base URL: https://api.example.com
Authentication: Bearer Token
Sample API: GET /users, POST /users, PUT /users/{id}, DELETE /users/{id}
5. Manual API Testing Using Postman
5.1 Steps:
Open Postman and create a new request.
Set the HTTP method (GET, POST, PUT, DELETE, etc.).
Enter the API URL.
Set authentication (Bearer Token).
Add Headers (e.g., Content-Type: application/json).
Provide request body (for POST/PUT methods).
Click Send and validate the response status code, body, headers.
Save test cases in Postman Collections for future reference.
5.2 Expected Results:
Status Code: 200 (Success), 201 (Created), 400 (Bad Request), 401 (Unauthorized), 404 (Not Found), 500 (Server Error)
Validate response body structure.
Verify response time and headers.
6. Automated API Testing Using Python
6.1 Setup
领英推荐
pip install requests pytest selenium
6.2 Sample API Test Script
import requests
import pytest
def test_get_users():
url = "https://api.example.com/users"
headers = {"Authorization": "Bearer YOUR_TOKEN"}
response = requests.get(url, headers=headers)
assert response.status_code == 200
assert "users" in response.json()
def test_create_user():
url = "https://api.example.com/users"
headers = {"Authorization": "Bearer YOUR_TOKEN", "Content-Type": "application/json"}
payload = {"name": "John Doe", "email": "[email protected]"}
response = requests.post(url, json=payload, headers=headers)
assert response.status_code == 201
assert response.json()["name"] == "John Doe"
6.3 Running Tests
pytest test_api.py
7. UI Automation with Selenium (If Needed)
If API data needs to be verified on UI:
from selenium import webdriver
def test_ui_login():
driver = webdriver.Chrome()
driver.get("https://example.com/login")
assert "Login" in driver.title
driver.quit()
8. Conclusion
This PoC demonstrates how to perform API testing manually using Postman and automate it using Python (Requests & Selenium). Future enhancements include integration with CI/CD pipelines for continuous testing.
9. Next Steps
Enhance test coverage with negative test cases.
Implement reporting mechanisms.
Integrate with Jenkins for automation in CI/CD pipeline.