Playwright Installation Made Simple
Playwright can be installed on Windows, macOS and Linux. For Python automation, we install the Playwright Python package and then install the browser binaries required by Playwright.
Windows
Install Python, Playwright and browsers using PowerShell or Command Prompt.
macOS
Install using Terminal with Python and pip or a Python virtual environment.
Linux
Install Playwright and browser dependencies from Terminal.
VS Code
Create a Playwright project and execute tests directly from VS Code.
Python
Python should be installed and available from the terminal.
python --version
Virtual Environment
A virtual environment keeps Playwright dependencies isolated for each project.
python -m venv .venv
VS Code
VS Code provides an easy environment for writing, debugging and running Playwright tests.
Step 1 — Open PowerShell
Open PowerShell or Command Prompt and verify Python.
python --version
pip --version
Step 2 — Create a Project
mkdir playwright-demo
cd playwright-demo
python -m venv .venv
Step 3 — Activate Virtual Environment
.venv\Scripts\activate
Step 4 — Install Playwright
pip install playwright
Step 5 — Install Browsers
playwright install
The Playwright Python package and supported browser binaries are now available to your project.
Step 1 — Open Terminal
python3 --version
pip3 --version
Step 2 — Create Project
mkdir playwright-demo
cd playwright-demo
python3 -m venv .venv
Step 3 — Activate Environment
source .venv/bin/activate
Step 4 — Install Playwright
pip install playwright
Step 5 — Install Browsers
playwright install
If your system uses python3 and pip3, continue using those commands when creating the environment.
Step 1 — Verify Python
python3 --version
Step 2 — Create Environment
mkdir playwright-demo
cd playwright-demo
python3 -m venv .venv
Step 3 — Activate Environment
source .venv/bin/activate
Step 4 — Install Playwright
pip install playwright
Step 5 — Install Browsers and Dependencies
playwright install
playwright install-deps
On Linux, browser operating-system dependencies may be required. The playwright install-deps command can install the required dependencies on supported Linux distributions.
Installing the Python package and installing the Playwright browser binaries are separate steps.
Open the Project
Open your playwright-demo folder in VS Code.
Select Python Interpreter
Select the Python interpreter from your .venv environment.
Create Test Folder
playwright-demo/
│
├── .venv/
│
├── tests/
│ └── test_login.py
│
└── requirements.txt
Install pytest
pip install pytest
After installation, let's open a real website and verify its page title.
from playwright.sync_api import sync_playwright
def test_open_website():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://example.com")
print(page.title())
browser.close()
Run the Test
A Chromium browser window opens, navigates to the specified website, prints the page title and closes.
Imagine your application has a login page. Playwright can automate entering credentials and verifying the logged-in page.
from playwright.sync_api import sync_playwright
def test_login():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://your-application.example/login")
page.get_by_label("Username").fill("testuser")
page.get_by_label("Password").fill("Password123")
page.get_by_role("button", name="Login").click()
page.wait_for_url("**/dashboard")
assert "Dashboard" in page.title()
browser.close()
Do not hard-code real production passwords or API secrets inside test source code. Use environment variables or a secure secret-management system.
Playwright can install its supported browser binaries individually when you do not need every browser.
playwright install chromium
playwright install firefox
playwright install webkit
If your team only needs Chromium-based automated tests, installing Chromium specifically can reduce unnecessary browser downloads.
A major benefit of Playwright is the ability to automate Chromium, Firefox and WebKit through a consistent API.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browsers = [
p.chromium,
p.firefox,
p.webkit
]
for browser_type in browsers:
browser = browser_type.launch()
page = browser.new_page()
page.goto("https://example.com")
print(
browser_type.name,
"=>",
page.title()
)
browser.close()
The same smoke test can be executed against multiple browser engines to detect browser-specific problems.
| Environment | Python Check | Virtual Environment | Activate | Playwright | Browsers |
|---|---|---|---|---|---|
| Windows | python --version |
python -m venv .venv |
.venv\Scripts\activate |
pip install playwright |
playwright install |
| macOS | python3 --version |
python3 -m venv .venv |
source .venv/bin/activate |
pip install playwright |
playwright install |
| Linux | python3 --version |
python3 -m venv .venv |
source .venv/bin/activate |
pip install playwright |
playwright install |
❌ 'python' is not recognized
Your Python executable may not be available through the system PATH.
Check whether python3 works, or verify your Python installation and PATH configuration.
❌ Playwright browser missing
The Python package may be installed while the required browser binary has not been installed.
playwright install
❌ Linux dependency error
Some Linux systems require additional operating system libraries for browsers.
playwright install-deps
❌ Wrong Python Environment
The package might have been installed into a different Python environment.
python -m pip show playwright
Run the following command to confirm that Playwright can launch a browser.
python -c "from playwright.sync_api import sync_playwright; print('Playwright is installed successfully')"
playwright-demo/
│
├── .venv/
│
├── tests/
│ ├── test_login.py
│ ├── test_search.py
│ └── test_checkout.py
│
├── pages/
│ ├── login_page.py
│ ├── home_page.py
│ └── checkout_page.py
│
├── test-data/
│ └── users.json
│
├── requirements.txt
│
└── README.md
Keep application page objects, tests and test data separated as your automation project grows.
Imagine a QA engineer joins a project where the application needs to be tested every day.
playwright
pytest
A new team member can then create the environment and install the same dependencies with:
python -m venv .venv
# Activate the environment
pip install -r requirements.txt
playwright install
In a CI/CD environment, the automation machine should install the Python dependencies and Playwright browsers before executing tests.
python -m pip install --upgrade pip
pip install -r requirements.txt
playwright install
pytest
CI environments vary. Linux runners may also require browser operating-system dependencies, depending on the runner image and configuration.
From Installation to Real Automation
Playwright installation is essentially a two-part process for Python projects: install the Python package and install the browser binaries. Once those steps are complete, you can build tests for login, search, checkout, forms, APIs, multi-browser scenarios and other modern web applications.
After completing installation, the next practical lesson is to create your first Playwright framework using Page Object Model, pytest, reusable fixtures, screenshots and reporting.