2. Environment Setup
Playwright with Python · 244 pages source format
venv hygiene, install pytest-playwright + browser binaries, and a starter folder structure that won’t fight you when POM arrives.
What you'll learn
- Always use a virtual environment
- pip install vs playwright install
- Starter project layout
Python, pip, and virtual environments
Assuming Python is installed, the critical habit here is virtual environments (venv). Every project should get its own isolated environment.
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # WindowsInteractive study board
Installing Playwright + browser binaries
Two separate steps that beginners often miss the distinction between.
pip install pytest-playwright
playwright installPro tip. Playwright ships its own browsers on purpose — same version on every laptop and CI machine.
Interactive study board
Project folder structure
Even a simple starting structure pays off later (preview of Chapter 14’s POM and Chapter 29’s scalable architecture). Starting with this loose structure — rather than dumping every test file flat in one folder — means you won’t need a painful reorganization once the suite grows past a handful of tests.
project/
├── tests/
├── pages/ # page object classes — comes later
├── conftest.py
├── pytest.ini
└── requirements.txtDo this now
Create this folder skeleton in a new repo and commit an empty tests/.gitkeep.