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.
-
Page Object Model (POM)
All page-specific locators and actions live in dedicated Page classes (pages/
), keeping test logic clean and maintainable. -
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.
-
Multi-Browser & Headless Support
Use--browsers
to select any combination ofchromium,firefox,webkit
, and--headless
to run without a visible UI. Parallelize with-n auto
(pytest-xdist).
-
Clone the repository
git clone https://github.com/linkenmin/practicetestautomation-playwright.git cd practicetestautomation-playwright
-
Create & activate a virtual environment
python3 -m venv .venv source .venv/bin/activate
-
Install Python dependencies
pip install --upgrade pip pip install --no-cache-dir -r requirements.txt
- 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
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 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
├── 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`)