Skip to content

snnarangsumit/Playwright-pytest-framework

Repository files navigation

Playwright Pytest Automation Framework

Python Playwright Pytest Allure

This repository contains a production-ready hybrid automation framework built using Python, Playwright, and Pytest.
It demonstrates how to design and scale a real-world UI + API test framework with clean architecture, CI integration, parallel execution, and professional reporting.


🚀 Technology Stack

  • Python
  • Playwright (UI automation)
  • Pytest
  • Requests (API automation)
  • Pytest Fixtures
  • Pytest-xdist (parallel execution)
  • Allure Reporting
  • GitHub Actions (CI)
  • Page Object Model (POM)

🧱 Key Design Principles

  • Clear separation of concerns between UI, API, and test logic
  • Page Object Model (POM) for maintainable UI automation
  • Reusable API client abstraction for scalable API testing
  • API → UI integration pattern for end-to-end validation
  • Centralized browser and test lifecycle management
  • Environment-based configuration (no hard-coded values)
  • Automatic screenshot capture on test failure
  • Parallel execution for faster feedback
  • CI-ready design with GitHub Actions

📁 Project Structure

Playwright-pytest-framework/
├── tests/
│   ├── ui/                     # UI test cases
│   └── api/                    # API test cases
├── pages/                      # Page Object classes
├── api/                        # API framework layer (clients)
├── config/                     # Environment configuration
├── screenshots/                # Screenshots captured on failures
├── allure-results/             # Allure raw test results
├── .github/workflows/          # GitHub Actions CI
├── conftest.py                 # Pytest fixtures and hooks
├── pytest.ini                  # Pytest configuration
├── requirements.txt            # Dependencies
└── README.md

⚙️ Setup Instructions

Install dependencies

pip install -r requirements.txt
playwright install

▶️ Run Tests

Run all tests (UI + API)

pytest

Run tests in parallel

pytest -n auto

🌍 Environment Configuration

Tests run against the QA environment by default.

To switch environment:

ENV=prod pytest

Environment values are managed centrally to keep tests flexible and clean.


🧪 Example Tests

UI Test (Page Object based)

def test_smoke(page):
    home = HomePage(page)
    home.open()
    assert home.get_title() == "Example Domain"

API Test (Framework-based)

def test_get_users():
    users_api = UsersAPI()
    response = users_api.get_users()
    assert response.status_code == 200

API → UI Integration Test

def test_user_data_via_api_and_ui(page):
    users_api = UsersAPI()
    user = users_api.get_users().json()[0]

    home = HomePage(page)
    home.open()
    assert home.get_title() == "Example Domain"

📸 Failure Handling

  • Screenshots are automatically captured on UI test failures
  • Screenshots are stored in the screenshots/ directory
  • Screenshots are also attached directly to Allure reports

📊 Allure Reporting

Generate and view report locally

pytest
allure serve allure-results

Allure provides:

  • Unified UI + API reporting
  • Test history and execution details
  • Failure screenshots and logs

In CI, Allure results are stored as build artifacts.


🔄 Continuous Integration (CI)

This project uses GitHub Actions to:

  • Run tests on every push and pull request
  • Install dependencies and Playwright browsers
  • Execute tests headlessly
  • Generate and archive Allure results

CI ensures fast feedback and consistent test execution.


🎯 Purpose of This Framework

This repository showcases:

  • Enterprise-level automation framework design
  • Hybrid UI + API testing strategy
  • API framework abstraction and reuse
  • Parallel execution and CI integration
  • Maintainability over complexity

It is intended as a portfolio-quality project demonstrating real-world automation skills.


👤 Author

Sumit Narang
Senior QA / Automation Engineer

About

Modern hybrid automation framework with Playwright, Pytest for UI and API testing with Allure reporting

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages