Student Name: Nemat Sachdeva
Course: CSE3253 DevOps
Semester: VI
Project Type: DevOps Automation Tool
The API Test Generator is a DevOps automation tool that automatically generates pytest-based API test cases from OpenAPI 3.0 or Swagger 2.0 specifications. This tool eliminates manual test creation, accelerates the QA process, and seamlessly integrates into CI/CD pipelines.
OpenAPI / Swagger File
↓
SwaggerParser extracts endpoints
↓
APITestGenerator creates pytest tests
↓
pytest executes API tests
↓
Automated validation & reporting
- ✅ Automated API Testing - Generate tests automatically from specifications
- ✅ Faster QA Process - Reduce test creation time from hours to seconds
- ✅ DevOps Pipeline Integration - Seamlessly integrate with CI/CD workflows
- ✅ Reduced Manual Effort - Eliminate repetitive test writing tasks
- ✅ Consistent Test Coverage - Ensure all endpoints are tested
- ✅ Specification-Driven - Tests stay in sync with API documentation
- 🔍 Parse OpenAPI 3.0 and Swagger 2.0 specifications
- 🎯 Extract API endpoints automatically with methods, parameters, and responses
- 🧪 Generate production-ready pytest test cases with status code validation
▶️ Run Tests Directly from UI - Execute pytest dynamically and view results in real-time- 📋 Copy & Download Generated Tests - Easy code sharing and file management
- 🌐 Web UI for uploading Swagger files with drag-and-drop support
- 🐳 Docker containerized application for consistent deployment
- 🔄 CI/CD pipeline using GitHub Actions with 5-stage automation
- 📊 Monitoring configuration using Prometheus, Nagios, and Grafana
- ☸️ Kubernetes deployment manifests for production orchestration
- 📝 REST API endpoints for programmatic test generation
- 🎨 Modern dark-themed UI with responsive design and test result visualization
┌─────────────────────────────────────────────────────────────┐
│ User / CI/CD Pipeline │
└────────────────────────┬────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────┐
│ Web UI / REST API │
│ (Flask Backend) │
└────────────────────────┬────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────┐
│ SwaggerParser (Python) │
│ • Parses OpenAPI 3.0 / Swagger 2.0 │
│ • Extracts endpoints, methods, parameters │
│ • Validates specification structure │
└────────────────────────┬────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────┐
│ APITestGenerator (Python) │
│ • Generates pytest test functions │
│ • Creates status code assertions │
│ • Adds endpoint logging │
└────────────────────────┬────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────┐
│ Generated pytest Tests │
│ • test_get_endpoint_1() │
│ • test_post_endpoint_2() │
│ • test_put_endpoint_3() │
└────────────────────────┬────────────────────────────────────┘
│
↓
┌─────────────────────────────────────────────────────────────┐
│ CI/CD Pipeline Execution │
│ • Automated test execution │
│ • Coverage reporting │
│ • Docker image building │
└─────────────────────────────────────────────────────────────┘
- Python 3.11 - Core programming language
- Flask 3.0 - Web framework for REST API
- PyYAML 6.0 - YAML parsing for Swagger files
- jsonschema 4.20 - JSON validation
- pytest 7.4 - Test framework
- requests 2.31 - HTTP client for API testing
- pytest-cov - Code coverage reporting
- selenium 4.15 - UI automation testing
- Docker - Containerization
- Docker Compose - Multi-container orchestration
- GitHub Actions - CI/CD automation
- Kubernetes - Container orchestration (manifests included)
- Prometheus - Metrics collection and alerting
- Nagios - System monitoring
- Grafana - Visualization dashboards
- flake8 - Linting
- black - Code formatting
- isort - Import sorting
- pylint - Static code analysis
API-TEST-GENERATOR/
│
├── src/main/ # Application source code
│ ├── app.py # Flask REST API server
│ ├── parser.py # SwaggerParser class
│ ├── test_generator.py # APITestGenerator class
│ ├── config/ # Configuration files
│ │ └── config.yaml # Application settings
│ └── static/ # Frontend UI
│ ├── index.html # Main UI page
│ ├── style.css # Styles (dark theme)
│ └── script.js # Frontend JavaScript
│
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ │ └── test_swagger_parser.py # Parser tests
│ ├── integration/ # Integration tests
│ │ └── test_app.py # API endpoint tests
│ └── selenium/ # UI automation tests
│ └── test_ui.py # Selenium tests
│
├── infrastructure/ # Infrastructure as Code
│ ├── docker/ # Docker configuration
│ │ ├── Dockerfile # Container image definition
│ │ └── docker-compose.yml # Service orchestration
│ └── kubernetes/ # Kubernetes manifests
│ ├── deployment.yaml # Deployment (3 replicas)
│ ├── service.yaml # LoadBalancer service
│ ├── configmap.yaml # Configuration
│ └── ingress.yaml # Ingress rules
│
├── monitoring/ # Monitoring configuration
│ ├── nagios/ # Nagios config
│ │ └── api-test-generator.cfg # Service monitoring
│ ├── alerts/ # Prometheus alerts
│ │ └── alert-rules.yaml # Alert definitions
│ ├── dashboards/ # Grafana dashboards
│ │ └── grafana-dashboard.json # Visualization
│ ├── health-check.sh # Health check script
│ └── prometheus.yml # Prometheus config
│
├── docs/ # Project documentation
│ ├── project-plan.md # Project planning
│ ├── design-document.md # Technical design
│ ├── user-guide.md # User documentation
│ └── api-documentation.md # API reference
│
├── .github/workflows/ # CI/CD pipeline
│ └── ci-cd.yml # GitHub Actions workflow
│
├── pytest.ini # Pytest configuration
├── requirements.txt # Python dependencies
├── Makefile # Build commands
├── .gitignore # Git ignore patterns
├── .dockerignore # Docker ignore patterns
└── README.md # This file
- Python 3.11 or higher
- pip (Python package manager)
- Git
- Docker (optional, for containerized deployment)
git clone https://github.com/NematSachdeva/API-Test-Generator.git
cd API-Test-Generator# Create virtual environment
python -m venv venv
# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtpython src/main/app.pyOpen your browser and navigate to:
- Web UI: http://localhost:8080/ui
- API Docs: http://localhost:8080/
- Health Check: http://localhost:8080/health
# Build Docker image
make docker-build
# Run container
make docker-run
# Access UI
# Open http://localhost:8080/ui in your browser
# View logs
make docker-logs
# Stop container
make docker-stop
# Clean up
make docker-clean# Build Docker image
docker build -f infrastructure/docker/Dockerfile -t api-test-generator:latest .
# Run container
docker run -d -p 8080:8080 --name api-test-generator api-test-generator:latest
# Access UI
# Open http://localhost:8080/ui
# View logs
docker logs -f api-test-generator
# Stop and remove container
docker stop api-test-generator
docker rm api-test-generator# Start all services
docker-compose -f infrastructure/docker/docker-compose.yml up -d
# View logs
docker-compose -f infrastructure/docker/docker-compose.yml logs -f
# Stop services
docker-compose -f infrastructure/docker/docker-compose.yml downThe API Test Generator now includes a Run Tests feature directly in the web interface:
-
Generate Tests
- Upload your Swagger/OpenAPI file
- Click "Generate Tests"
- Tests appear in the code viewer
-
Run Tests from UI
- Click the "Run Tests" button
- Backend executes pytest dynamically
- Results display in real-time with:
- ✅ Test summary card (passed, failed, total)
- 📋 Individual test results with status
- 🖥️ Environment info (Python, pytest versions)
- 📊 Execution time
- 🔍 Console output (collapsible)
-
View Results
- Green checkmarks for passed tests
- Red X marks for failed tests
- Click "View Code" to see generated test code again
- Click "View Console Output" for detailed pytest output
pip install pytest requests# Run all tests
pytest generated_tests.py
# Run with verbose output
pytest generated_tests.py -v
# Run with detailed output
pytest generated_tests.py -vv
# Run with coverage
pytest generated_tests.py --cov=. --cov-report=htmlgenerated_tests.py::test_get_users_1 PASSED [ 33%]
generated_tests.py::test_post_users_2 PASSED [ 66%]
generated_tests.py::test_get_users_id_3 PASSED [100%]
========================= 3 passed in 0.45s =========================
The generated tests automatically:
- ✅ Send HTTP requests to each endpoint
- ✅ Validate response status codes (200, 201, 404, etc.)
- ✅ Print endpoint names for debugging
- ✅ Use the requests library for HTTP calls
- ✅ Follow pytest conventions and best practices
The backend provides a /run-tests endpoint for programmatic test execution:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"test_code": "import pytest\n..."}' \
http://localhost:8080/run-testsResponse:
{
"stdout": "===== test session starts =====\n...",
"stderr": "",
"returncode": 0,
"passed": true,
"summary": "3 passed in 0.45s"
}-
Open the UI
- Navigate to http://localhost:8080/ui
-
Upload Swagger/OpenAPI File
- Drag and drop your
.jsonor.yamlfile - Or click "browse" to select a file
- Drag and drop your
-
Click "Generate Tests"
- Wait for processing (usually < 1 second)
-
Download Generated Tests
- Click "Download" button
- Or click "Copy" to copy to clipboard
- Save as
generated_tests.py
curl -X POST \
-F "file=@swagger.json" \
http://localhost:8080/generate-tests \
| jq -r '.test_code' > generated_tests.pycurl -X POST \
-H "Content-Type: application/json" \
-d @swagger.json \
http://localhost:8080/generate-tests \
| jq -r '.test_code' > generated_tests.pycurl -X POST \
-H "Content-Type: application/json" \
-d @swagger.json \
http://localhost:8080/parsepip install pytest requests# Run all tests
pytest generated_tests.py
# Run with verbose output
pytest generated_tests.py -v
# Run with detailed output
pytest generated_tests.py -vvgenerated_tests.py::test_get_users_1 PASSED [ 33%]
generated_tests.py::test_post_users_2 PASSED [ 66%]
generated_tests.py::test_get_users_id_3 PASSED [100%]
========================= 3 passed in 0.45s =========================
The generated tests automatically:
- ✅ Send HTTP requests to each endpoint
- ✅ Validate response status codes (200, 201, 404, etc.)
- ✅ Print endpoint names for debugging
- ✅ Use the requests library for HTTP calls
- ✅ Follow pytest conventions and best practices
The project includes a comprehensive GitHub Actions CI/CD pipeline that runs automatically on every push and pull request.
- Sets up Python 3.11 environment
- Installs all packages from
requirements.txt - Caches pip packages for faster builds
- Verifies installations (Flask, pytest, PyYAML, requests, selenium)
- flake8 - Code style validation
- black - Code formatting check
- isort - Import sorting validation
- pylint - Static code analysis
- Executes pytest test suite (unit + integration)
- Sets PYTHONPATH for module imports
- Generates code coverage reports
- Uploads coverage to Codecov
- Result: 13 tests pass, 3 skipped (Selenium in CI)
- Sets up Docker Buildx
- Builds container image with caching
- Extracts metadata for tagging
- Validates successful build
- Pushes image to GitHub Container Registry
- Only runs on
mainanddevelopbranches - Tags with branch name, version, and commit SHA
- Authenticates with GitHub token
The pipeline runs automatically on:
- Push to
mainordevelopbranches - Pull requests to
mainordevelopbranches - Manual workflow dispatch
- Go to: https://github.com/NematSachdeva/API-Test-Generator
- Click the "Actions" tab
- View workflow runs and their status
- Click on a run to see detailed logs
# Run tests locally
./run_tests.sh all
# Run linting
flake8 src/ tests/ --max-line-length=120
# Check formatting
black --check src/ tests/
# Run tests with coverage
pytest tests/ --cov=src/main --cov-report=htmlThe project includes comprehensive monitoring configuration for production deployments.
- Location:
monitoring/prometheus.yml - Purpose: Collects application metrics
- Metrics:
- Request rate
- Response time
- Error rate
- CPU and memory usage
- Location:
monitoring/nagios/api-test-generator.cfg - Purpose: System health monitoring
- Checks:
- HTTP health endpoint
- API response time
- Container status
- Service availability
- Location:
monitoring/dashboards/grafana-dashboard.json - Purpose: Visual monitoring dashboards
- Panels:
- Service uptime
- Request rate graph
- Response time graph
- Error rate graph
- Memory usage
- CPU usage
- Location:
monitoring/alerts/alert-rules.yaml - Alerts:
- Service down (critical)
- High response time (warning)
- High error rate (warning)
- High memory usage (warning)
- High CPU usage (warning)
- Container restarting (warning)
-
Smarter Request Payload Generation
- Automatically generate request bodies from schema
- Support for complex nested objects
- Faker integration for realistic test data
-
Dynamic Parameter Handling
- Auto-generate path parameters
- Query parameter combinations
- Header and cookie handling
-
Response Schema Validation
- Validate response structure against OpenAPI schema
- Check data types and required fields
- Validate response examples
-
Automatic API Mocking
- Generate mock servers from specifications
- Support for contract testing
- Integration with Postman/Insomnia
-
Full Selenium UI Automation
- Complete UI test coverage
- Cross-browser testing
- Visual regression testing
-
Advanced Features
- Authentication token management
- Rate limiting tests
- Performance testing integration
- GraphQL support
- gRPC support
For detailed information, refer to:
- Project Plan - Project roadmap and timeline
- Design Document - Architecture and design patterns
- User Guide - Step-by-step usage instructions
- API Documentation - Complete REST API reference
# Run all tests
./run_tests.sh all
# Run unit tests only
./run_tests.sh unit
# Run integration tests only
./run_tests.sh integration
# Run with coverage report
./run_tests.sh coverage# Set PYTHONPATH
export PYTHONPATH=$PYTHONPATH:$(pwd)/src/main
# Run all tests
pytest tests/ -v
# Run specific test suite
pytest tests/unit/ -v
pytest tests/integration/ -v
# Run with coverage
pytest tests/ --cov=src/main --cov-report=html# Find process using port 8080
lsof -i :8080
# Kill the process
kill -9 <PID># Set PYTHONPATH
export PYTHONPATH=$PYTHONPATH:$(pwd)/src/main
# Or run with the test script
./run_tests.sh all# Clean Docker cache
docker system prune -a
# Rebuild without cache
docker build --no-cache -f infrastructure/docker/Dockerfile -t api-test-generator:latest .For issues, questions, or suggestions:
- Check the documentation
- Review the troubleshooting section
- Open an issue on GitHub
This project is created for educational purposes as part of the CSE3253 DevOps course.
Project: API Test Generator from OpenAPI/Swagger Specifications
Student: Nemat Sachdeva
Course: CSE3253 DevOps
Semester: VI
Institution: [Your University Name]
Year: 2026
- OpenAPI Initiative for specification standards
- Flask community for the web framework
- pytest community for the testing framework
- Docker for containerization technology
- GitHub for CI/CD infrastructure
| Task | Command |
|---|---|
| Install dependencies | pip install -r requirements.txt |
| Run application | python src/main/app.py |
| Access UI | http://localhost:8080/ui |
| Run tests | ./run_tests.sh all |
| Build Docker image | make docker-build |
| Run Docker container | make docker-run |
| View logs | make docker-logs |
| Stop container | make docker-stop |
| Run linting | flake8 src/ tests/ |
| Format code | black src/ tests/ |
| Generate coverage | pytest tests/ --cov=src/main |
Made with ❤️ for DevOps Automation