This test automation framework combines Playwright, pytest, and pytest-bdd to create a comprehensive solution for testing web applications. This project uses as example the Cypress Real World App, a popular open-source project that provides a realistic web application for testing purposes.
- Hybrid test strategy — Web UI with pytest-bdd (Gherkin) and API tests with plain pytest
- Page Object Model — Locators, actions, and assertions isolated from step definitions
- Thin BDD steps — Steps only orchestrate; all Playwright logic lives in page objects
- Resilient locators — Prefer
get_by_roleandget_by_test_id(data-test) (modified playwright configuration) - Auth state reuse — Login once, persist
storage_stateunder.auth/for faster scenarios - Test data seeding — Using class
UserBuilderto create users via API - Test isolation —
@reset_dbmarker reseeds the database after tagged scenarios - Centralized config — Base URLs and seed users via env vars /
config/ - CI/CD pipeline — Optimized with dependency caching
- Reporting — Allure reports published to GitHub Pages; Playwright traces on failure
- BDD skills — Skill to convert specification in natural language into framework-compliant tests
- Flaky retries — By default tests do not rerun. Only scenarios marked @flaky retry up to 2 times with 1s delay
- Parallelization — Tests run in parallel to speed up execution time with python-xdist
| Technology | Purpose |
|---|---|
| Playwright | E2E test runner and automation library |
| Requests | API testing and backend test setup |
| Python | Primary programming language |
| Gherkin (Cucumber) | BDD syntax for writing test scenarios |
| Git/GitHub | Version control and project hosting |
| Github Actions | Continuous integration pipeline |
| Github Pages | Artifact repository for Alure reports |
| Pytest | Test runner and orquestation |
| pytest-bdd | BDD integration with Gherkin scenarios |
| pytest-playwright | Browser fixtures and Playwright integration for pytest |
Allure reports are generated and published in https://codecaballero.github.io/python-playwright/
| Tool | Version |
|---|---|
| Python | 3.12+ |
| Node.js | 22+ |
| Yarn | latest |
The app under test must be available at:
- Web:
http://localhost:3000 - API:
http://localhost:3001
- Python 3.12 or higher
- uv installed
git clone https://github.com/CodeCaballero/python-playwright.git
cd python-playwrightuv sync
uv run playwright install chromium
uv run pytestIn a separate terminal:
git clone https://github.com/CodeCaballero/cypress-realworld-app.git app
cd app
yarn install --frozen-lockfile
yarn db:seed:dev
yarn devWait until both http://localhost:3000 and http://localhost:3001 respond.
Defaults are set in pyproject.toml:
| Variable | Default |
|---|---|
WEB_BASE_URL |
http://localhost:3000 |
API_BASE_URL |
http://localhost:3001 |
Override them when needed:
WEB_BASE_URL=http://localhost:3000 API_BASE_URL=http://localhost:3001 pytest# Full suite
pytest -v
# API only
pytest test/api/ -v
# Web (BDD) only
pytest test/web/ -v
# With Allure results
pytest -v --alluredir=allure-results
allure serve allure-results
# Playwright traces on failure
pytest test/web/ -v --tracing=retain-on-failure