Skip to content

linkenmin/practicetestautomation-playwright

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

practicetestautomation-playwright

This project demonstrates end-to-end browser-based UI testing using Python, Playwright, and Pytest for the practice login site: https://practicetestautomation.com/practice-test-login/. It provides a clean, modular test framework for Chromium, Firefox, and WebKit browsers with parallel execution support.

Design Philosophy

  1. Page Object Model (POM)
    All page-specific locators and actions live in dedicated Page classes (pages/), keeping test logic clean and maintainable.

  2. Pytest Fixtures for Setup & Teardown

    • Session-scoped fixtures launch Playwright and multiple browser instances only once per test run.
    • Function-scoped fixtures create fresh browser contexts and pages per test, ensuring isolation and reliable cleanup.
  3. Multi-Browser & Headless Support
    Use --browsers to select any combination of chromium,firefox,webkit, and --headless to run without a visible UI. Parallelize with -n auto (pytest-xdist).


Installation

  1. Clone the repository

    git clone https://github.com/linkenmin/practicetestautomation-playwright.git
    cd practicetestautomation-playwright
  2. Create & activate a virtual environment

    python3 -m venv .venv
    source .venv/bin/activate
  3. Install Python dependencies

    pip install --upgrade pip
    pip install --no-cache-dir -r requirements.txt

Run the Tests

  • Select browsers
    pytest --browsers=chromium,firefox,webkit
    pytest --browsers=chromium
  • Headless mode
    pytest --headless
  • Parallel execution
    pytest -n auto
  • All combined
    pytest --headless --browsers=chromium,firefox,webkit -n auto 

Docker Integration

This project includes a Dockerfile based on the official Playwright Python image. You can build and run your tests inside Docker to ensure consistency across environments.

FROM mcr.microsoft.com/playwright/python:v1.51.0-jammy
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["pytest", "--headless", "-n", "auto"]

Build & Run

  • Build the image (on AMD64 hosts):

    docker build -t practicetestautomation-playwright .
  • For Apple Silicon / ARM64, use Buildx to target AMD64:

    docker buildx build --platform=linux/amd64 -t practicetestautomation-playwright .
  • Run the container:

    docker run --rm practicetestautomation-playwright

Project Structure

├── pages/                    # Page Object classes encapsulating page interactions
│   ├── base_page.py
│   ├── login_page.py
│   └── secure_page.py
└── tests/                    # Test class with positive and negative login scenarios
│   └── test_case.py          
├── utils/                    # Helpers to initialize Playwright and launch browsers
│   └── browser_utils.py      
├── conftest.py               # Pytest fixtures for Playwright setup, browser instances, and per-test contexts
├── pytest.ini                # Marker definitions (`functional`, `negative`)
└── requirements.txt          # Python dependencies (`playwright`, `pytest`, `pytest-xdist`)

About

This project demonstrates end-to-end browser-based UI testing using Python, Playwright, and Pytest for the practice login site: https://practicetestautomation.com/practice-test-login/

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published