← All projects

Featured project 6 · Python · API + UI

Python pytest + Playwright Framework

API, UI and hybrid test automation in Python with pytest, Playwright, requests and pydantic: 46 tests of a notes app in about 1 m 45 s with 4 parallel workers, on Chromium, Firefox and WebKit in GitHub Actions.

Live CI status of Python pytest + Playwright Framework

View source code View documentation View latest CI runs View test report

Purpose

Shows a Python test stack for one application with a web UI and a REST API on the same backend: the public Expand Testing Notes app. The API carries most of the checks, the browser checks what a user sees, and hybrid tests check that the two sides agree.

Technology stack

AreaTools
LanguagePython 3.12
Test runnerpytest 9 (fixtures, markers, parametrize, hooks)
Browser automationPlaywright for Python 1.63 with pytest-playwright (Chromium, Firefox, WebKit)
APIrequests 2.34 (one Session per client)
Contractspydantic 2 models with extra fields forbidden
Parallel runs and reportpytest-xdist, pytest-html (one self-contained file), Playwright traces and videos
Code quality and CIruff (lint + format), GitHub Actions: lint gate, API job, browser matrix, nightly run

Architecture overview

tests/api, tests/ui, tests/e2e        what is checked
      │  fixtures (tests/conftest.py): throwaway user per test, logged-in client,
      │  page with ads blocked, page already logged in, report hooks
      │
framework/api        NotesApiClient (requests) + pydantic models
framework/pages      LoginPage, NotesPage (data-testid locators, no assertions)
framework/data       unique users and notes (uuid)
      │
framework/config     URLs and timeouts from environment variables

Key engineering decisions

Implemented features

Setup and execution

python -m venv .venv && .venv\Scripts\activate
pip install -r requirements.txt
playwright install chromium firefox webkit
pytest -n 4                              # all 46 tests
pytest -m api                            # API only
pytest -m "ui or e2e" --browser firefox  # browser tests on Firefox
pytest -m demo                           # report demo: 2 failed, 1 skipped, 1 xfailed

Sample test results

pytest-html report: 46 tests passed
pytest-html report of a full run: 46 passed.
pytest-html report of the demo run with failures, a skip and an xfail
The report demo: a UI failure with its screenshot, an API failure with the API's message, a strict xfail and a skip.

CI workflow

On every push, pull request and night: ruff lint and format check first, then the API tests with 4 workers and the UI + hybrid tests on Chromium, Firefox and WebKit as three parallel jobs. Each job writes a pass/fail table to the run summary and keeps its HTML report and traces as an artifact.

Known limitations and future improvements

Limitations

Next steps