Skip to content

A comprehensive Python-based API testing framework designed for Library Management Systems. Features include HAR parsing, multi-environment support, and detailed HTML reports.

License

Notifications You must be signed in to change notification settings

lkumarra/library-api-test-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyAPITest - Library Management API Testing Framework

Python Pytest Requests License

A comprehensive API testing framework built with Python, specifically designed for testing Library Management Systems. This framework provides automated testing capabilities with proper structure, configuration management, reporting, and documentation.

Features

  • 🚀 Automated test case generation from HAR files
  • 🌍 Multi-environment configuration support
  • 📊 Comprehensive HTML test reports
  • 📝 Detailed logging and debugging capabilities
  • 🔧 Reusable test utilities and components
  • 🔄 Session management for efficient API calls
  • 📚 Extensive documentation

Project Structure

lib-management-automation/
├── config/              # Configuration files
│   ├── config.yaml     # Environment configurations
│   └── logging_config.json  # Logging settings
├── docs/               # Detailed documentation
│   └── framework.md    # Framework documentation
├── reports/            # Test reports and logs
├── scripts/            # Utility scripts
│   └── generate_tests.py  # Test generation script
├── tests/              # Test files
│   ├── test_cases/    # Generated test cases
│   ├── base_test.py   # Base test class
│   └── conftest.py    # Pytest configuration
├── utilities/          # Framework utilities
│   ├── api_client.py  # API client
│   ├── config_manager.py  # Configuration manager
│   ├── har_parser.py  # HAR file parser
│   └── test_generator.py  # Test generator
├── requirements.txt    # Project dependencies
├── pytest.ini         # Pytest configuration
└── README.md          # Project documentation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package installer)
  • virtualenv or venv

Quick Start

  1. Clone the repository:

    git clone <repository-url>
    cd lib-management-automation
  2. Create and activate virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure environment:

    • Copy your HAR file to project root
    • Update configuration in config/config.yaml
    • Set environment variables if needed
  5. Generate tests:

    python scripts/generate_tests.py
  6. Start the API server:

    # Make sure your API server is running at http://localhost:8980
    # The tests expect the server to be available at this URL
  7. Run tests:

    # Run all tests
    pytest
    
    # Run with HTML report
    pytest --html=reports/report.html
    
    # Run specific test file
    pytest tests/test_cases/test_specific.py
    
    # Run by marker
    pytest -m smoke
    
    # Run tests with different base URL
    ENV=qa pytest  # Uses the qa environment URL from config.yaml
    # Or override directly:
    API_TEST_BASE_URL="http://custom-api.example.com" pytest

Note: The tests require the API server to be running and accessible. If the server is not available, tests will be skipped with an appropriate message.

Configuration

Environment Settings

Configure different environments in config/config.yaml:

environments:
  dev:
    base_url: "http://localhost:8980"
    timeout: 30
  qa:
    base_url: "https://qa-api.example.com"
    timeout: 30

Environment Variables

  • ENV: Set environment (dev/qa/prod)
  • API_TEST_*: Override any config value

Example:

export ENV=qa
export API_TEST_BASE_URL="https://custom-api.example.com"

Test Reports

HTML reports are generated in the reports directory and include:

  • Test execution summary
  • Test case details and duration
  • Failure information and screenshots
  • Environment details

Logs are available in:

  • Console output
  • reports/test_execution_[timestamp].log

Development Guide

Creating Tests Manually

from tests.base_test import BaseTest

class TestExample(BaseTest):
    @pytest.mark.smoke
    def test_example(self):
        response = self.api_client.get('/endpoint')
        self.validate_response(
            response,
            expected_status_code=200,
            expected_values={'key': 'value'}
        )

Available Markers

  • @pytest.mark.smoke: Smoke tests
  • @pytest.mark.regression: Regression tests
  • @pytest.mark.api: API tests

Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A comprehensive Python-based API testing framework designed for Library Management Systems. Features include HAR parsing, multi-environment support, and detailed HTML reports.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages