- Install Cursor AI (recommended IDE)
- Clone/download project and open with Cursor AI (or PyCharm)
Make sure you have the following installed on your system:
- Python (version 3.7 or later)
- pip (Python package manager)
-
Create and activate a virtual environment
python -m venv .venv source venv/bin/activate # On macOS/Linux venv\Scripts\activate # On Windows
-
Install dependencies
pip install playwright pytest python -m pip install --upgrade pip pip install -r requirements.txt
-
Install pre-commit hooks
pre-commit install
Note: This step needs to be done manually after installing requirements. Pre-commit hooks (including Black formatter) cannot be installed automatically through requirements.txt as this is a Git security feature.
-
Install Playwright browsers
playwright install
-
Verify Playwright installation
python -c "import playwright; print(playwright.__version__)"
To execute your Playwright tests with pytest, run:
pytest
# Run all tests in the file
# Example:
pytest tests/test_auth.py
# Run a specific test
pytest tests/test_auth.py -k test_user_registration
pytest tests/test_auth.py -k test_user_login
# Run with more detailed output
pytest tests/test_auth.py -v
If you want to run Playwright tests in headed mode (with browser UI), use:
pytest --headed
For running tests in a specific browser, specify it as follows:
pytest --browser=chromium # or firefox, webkit
To store authentication tokens and other secrets securely, create a .env
file:
TOKEN=your_auth_token_here
Then, load environment variables in your test files using:
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TOKEN")
- Use
--slowmo
to slow down execution for debugging:pytest --headed --slowmo=500 # 500ms delay between steps
- Run tests in debug mode:
pytest --headed --debug
Playwright can generate tests for you by recording actions:
playwright codegen example.com
This opens a browser where you can perform actions, and Playwright generates the corresponding test script.
Happy Testing! 🚀