A modular, pytest-based Playwright framework for testing React applications (or any web apps) in Python. Built-in support for:
- Page Object Model (POM) for clean, maintainable test code
- Data-driven testing via JSON fixtures
- Visual regression with baseline snapshots and automatic diffs
- Screenshots & videos on failures for easier debugging
- Environment configuration using
.envfiles - Authenticated session reuse using Playwright's
storageState - HTML & JUnit reporting via
pytest-htmland JUnit XML - Optional Allure reporting for advanced dashboards
- CLI & CI integration with GitHub Actions and GitHub Pages
Integrating Husky ensures code quality before changes are committed. Although Husky is a Node.js tool, it works great for Python projects too.
-
Initialize Husky in your repo (requires Node.js):
npm init -y npm install husky --save-dev npx husky install
-
Add the install command to your
package.json:"scripts": { "prepare": "husky install" }
-
Create a pre-commit hook to run your tests and linters:
npx husky add .husky/pre-commit "pytest tests/ && black --check . && flake8" git add .husky/pre-commit
If you're new to QA or test automation, follow these steps to get this framework running on your machine.
- Python 3.8 or later installed
- Git installed
- Node.js installed (for optional Husky Git hooks)
- Google Chrome (for web automation visibility)
git clone https://github.com/your-username/your-python-repo.git
cd your-python-repopython -m venv .venv
source .venv/bin/activate # For macOS/Linux
# .\.venv\Scripts\activate # For Windowspip install -r requirements.txt
playwright installCopy the example file and edit it:
cp .env.example .envUpdate .env with your app URL and login credentials:
BASE_URL=https://your-app.com
LOGIN_EMAIL=your@email.com
LOGIN_PASSWORD=yourpasswordThis will log in and save a session token to reuse in tests:
python utils/save_storage_state.pypytestOpen the HTML report in your browser:
open reports/html/report.html # Mac
start reports\html\report.html # WindowsHusky helps make sure your code is clean before committing.
npm install
npx husky install
npx husky add .husky/pre-commit "pytest && black --check . && flake8"Now, every time you commit, it will check that your tests pass and code is formatted.
Now you can start:
- Writing tests inside the
tests/folder - Creating reusable components in
pages/using Page Object Model - Using data files in
fixtures/data/ - Viewing visual regression screenshots in
visual_regression/
| Action | Command |
|---|---|
| Run all tests | pytest |
| Run one test file | pytest tests/test_signup.py |
| Regenerate login session | python utils/save_storage_state.py |
| View HTML report | Open reports/html/report.html |
🔰 This project is beginner-friendly. If you follow the steps above, you’ll be up and running with a professional-grade test framework in minutes — no deep experience needed.