A professional, enterprise-grade API testing framework built with Python. This framework demonstrates modern testing practices including contract testing, data-driven testing, and comprehensive CI/CD integration.
- 📋 Overview
- ✅ Features
- 🗂️ Project Structure
- 🔌 API Endpoints
- ⚙️ Prerequisites
- 🛠️ Installation
- 🚀 Quick Start
- 🛠️ Development Setup
- 🧪 Running Tests
- 📊 Generating Reports
- 📊 Test Execution & Reports
- 🔍 Test Categories
- 👥 Contributing
- 🔐 Security
- 📚 Documentation
⚠️ Common Issues & Solutions- 🤝 Support
- 📄 License
This diagram shows how different components of the framework interact with each other.
This framework is designed to test the ReqRes Public API but can be adapted for any RESTful API. It incorporates:
- Contract Testing: JSON Schema validation ensures API responses match specifications
- Data-Driven Testing: Parameterized tests with various data sets
- Security Scanning: Integrated security checks with Bandit and Safety
- Performance Validation: Response time validation and performance test capabilities
- Comprehensive Reporting: Allure reports with detailed test analytics
- Modular and scalable folder structure
- Configurable environments (e.g. dev, staging)
- JSON Schema validation (contract testing)
- Data-driven POST testing
- Boundary and negative test cases
- Retry logic and timeouts
- Allure report integration
- Pytest markers and logging
- Compatible with CI/CD (via GitHub Actions)
- Isolated virtual environment in
.venv
API-Test-Automation-Framework/
├── .github/workflows/ # CI/CD pipeline configurations
│ └── ci.yml # Main workflow file
├── config/ # Environment & test configurations
│ └── config.yaml # Configuration parameters
├── data/ # Test data files
│ ├── large_payload.json # Large request payload testing
│ └── post_user_payloads.json # Data-driven test payloads
├── schemas/ # JSON Schema definitions
│ ├── create_user_schema.json # POST request validation
│ ├── single_user_schema.json # Single user response
│ └── user_list_schema.json # User list response
├── tests/ # Test suites
│ ├── test_api_validation.py # API contract tests
│ ├── test_error_scenarios.py # Error handling tests
│ ├── test_user_creation.py # User creation tests
│ └── test_user_retrieval.py # User retrieval tests
├── utils/ # Utility functions
│ └── api_utils.py # Common API operations
├── reports/ # Test execution reports
├── conftest.py # Pytest fixtures & configurations
├── pytest.ini # Pytest settings & markers
├── requirements.txt # Project dependencies
└── setup.sh # Environment setup script
This framework tests the ReqRes API, a hosted REST-API ready to respond to your AJAX requests. The following endpoints are covered:
- GET
/api/users
- List users with pagination - GET
/api/users/{id}
- Get single user by ID - POST
/api/users
- Create new user - PUT
/api/users/{id}
- Update existing user - PATCH
/api/users/{id}
- Partially update user - DELETE
/api/users/{id}
- Delete user
- POST
/api/login
- User login - POST
/api/register
- User registration - GET
/api/unknown
- List resources - GET
/api/unknown/{id}
- Get single resource
- ✅ Positive scenarios: Valid requests with expected responses
- ✅ Negative scenarios: Invalid requests, malformed data, non-existent resources
- ✅ Edge cases: Boundary values, empty payloads, special characters
- ✅ Performance: Response time validation
- ✅ Security: Input validation and error handling
- ✅ Contract testing: JSON schema validation for all responses
- Python 3.10 or higher
- Git
- Java Runtime Environment (JRE) for Allure reporting
- Bash-compatible shell (Git Bash for Windows users)
-
Clone the Repository:
git clone https://github.com/SaahilParmar/API-Test-Automation-Framework.git cd API-Test-Automation-Framework
-
Create Virtual Environment:
# Create .venv in project directory python -m venv .venv # Activate virtual environment # On Unix/macOS: source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install Dependencies:
# Upgrade pip python -m pip install --upgrade pip # Install project dependencies pip install -r requirements.txt
-
Install Allure (Required for reports):
On macOS:
brew install allure
On Linux:
sudo apt-add-repository ppa:qameta/allure sudo apt-get update sudo apt-get install allure
On Windows:
scoop install allure
-
Clone the repository:
git clone https://github.com/SaahilParmar/API-Test-Automation-Framework.git cd API-Test-Automation-Framework
-
Run the setup script (creates
.venv
and installs dependencies):./setup.sh
-
Activate the virtual environment:
source .venv/bin/activate # On Unix/macOS # or .venv\Scripts\activate # On Windows
-
Run the tests:
pytest tests/ -v # Run all tests pytest tests/ -m smoke # Run smoke tests only
-
Ensure you're using the correct virtual environment:
# You should see (.venv) in your prompt # If not, activate it: source .venv/bin/activate
-
Verify your setup:
python --version # Should match version in .github/workflows/ci.yml pip list # Should match requirements.txt
-
Install new dependencies:
pip install new-package pip freeze > requirements.txt # Update requirements
-
Run All Tests:
pytest tests/ -v
-
Run Specific Test Types:
pytest tests/ -m smoke # Smoke tests only pytest tests/ -m "not slow" # Skip slow tests
-
Run Tests in Parallel:
pytest tests/ -n auto
-
Generate Coverage Report:
pytest tests/ --cov=utils --cov-report=html
-
Generate Allure Report:
# Run tests with Allure pytest tests/ --alluredir=allure-results # Generate HTML report allure generate allure-results -o allure-report --clean
-
View Report:
allure serve allure-results
The report will automatically open in your default browser.
Example of a successful test execution showing all test categories passing
Comprehensive test results with trends, behaviors, and detailed test cases
HTML coverage report showing test coverage across the codebase
-
API Validation (
test_api_validation.py
):- Contract testing with JSON schemas
- Response headers validation
- Response time validation
-
Error Scenarios (
test_error_scenarios.py
):- 404 Not Found handling
- Invalid request handling
- Malformed data testing
-
User Operations (
test_user_*.py
):- CRUD operations testing
- Data-driven testing
- Edge cases
-
Create a new branch:
git checkout -b feature/your-feature-name
-
Run pre-commit checks:
pre-commit run --all-files
-
Run tests before committing:
pytest tests/ -v
The framework includes several security measures:
- Automated security scanning with Bandit
- Dependency vulnerability checking with Safety
- Pre-commit hooks for security checks
- Regular security updates via GitHub Actions
Detailed test documentation is available at: https://saahilparmar.github.io/API-Test-Automation-Framework/
The documentation is automatically updated on each successful merge to main.
-
Virtual Environment Issues:
# If .venv is not working: rm -rf .venv python -m venv .venv source .venv/bin/activate
-
Allure Report Generation Fails:
# Check Java installation: java -version # Reinstall Allure if needed: npm install -g allure-commandline
-
Test Failures:
- Ensure you're using Python 3.10+
- Verify all dependencies are installed
- Check API availability at https://reqres.in/
For issues and feature requests, please use the GitHub Issues tracker.
This project is licensed under the MIT License - see the LICENSE file for details.