Playwright Installation

Complete guide to installing Playwright on Windows, macOS, Linux and different development environments with real-time automation examples.

Python Playwright • Setup • Browsers • VS Code • Real-Time Examples
🚀 1. What We Will Learn

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.

🧰 2. Installation Requirements
Required

Python

Python should be installed and available from the terminal.

Check Python
python --version
Recommended

Virtual Environment

A virtual environment keeps Playwright dependencies isolated for each project.

Create Environment
python -m venv .venv
Useful

VS Code

VS Code provides an easy environment for writing, debugging and running Playwright tests.

🪟 3. Install Playwright on Windows
Windows + Python + Playwright

Step 1 — Open PowerShell

Open PowerShell or Command Prompt and verify Python.

PowerShell
python --version
pip --version

Step 2 — Create a Project

PowerShell
mkdir playwright-demo
cd playwright-demo

python -m venv .venv

Step 3 — Activate Virtual Environment

Windows
.venv\Scripts\activate

Step 4 — Install Playwright

Windows
pip install playwright

Step 5 — Install Browsers

Windows
playwright install
Installation complete!

The Playwright Python package and supported browser binaries are now available to your project.

🍎 4. Install Playwright on macOS
macOS + Python + Playwright

Step 1 — Open Terminal

Terminal
python3 --version
pip3 --version

Step 2 — Create Project

Terminal
mkdir playwright-demo
cd playwright-demo

python3 -m venv .venv

Step 3 — Activate Environment

Terminal
source .venv/bin/activate

Step 4 — Install Playwright

Terminal
pip install playwright

Step 5 — Install Browsers

Terminal
playwright install
macOS Tip:

If your system uses python3 and pip3, continue using those commands when creating the environment.

🐧 5. Install Playwright on Linux
Linux + Python + Playwright

Step 1 — Verify Python

Linux Terminal
python3 --version

Step 2 — Create Environment

Linux Terminal
mkdir playwright-demo
cd playwright-demo

python3 -m venv .venv

Step 3 — Activate Environment

Linux Terminal
source .venv/bin/activate

Step 4 — Install Playwright

Linux Terminal
pip install playwright

Step 5 — Install Browsers and Dependencies

Linux Terminal
playwright install
playwright install-deps
Linux Note:

On Linux, browser operating-system dependencies may be required. The playwright install-deps command can install the required dependencies on supported Linux distributions.

🔄 6. Complete Installation Flow
Install Python
→
Create Project
→
Create venv
→
pip install playwright
→
playwright install
→
Run Test
Important:

Installing the Python package and installing the Playwright browser binaries are separate steps.

💻 7. Playwright Installation with VS Code
1

Open the Project

Open your playwright-demo folder in VS Code.

2

Select Python Interpreter

Select the Python interpreter from your .venv environment.

3

Create Test Folder

Project Structure
playwright-demo/
│
├── .venv/
│
├── tests/
│   └── test_login.py
│
└── requirements.txt
4

Install pytest

Terminal
pip install pytest
🧪 8. Your First Real-Time Playwright Test

After installation, let's open a real website and verify its page title.

tests/test_first.py
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

$ python -m pytest -s
Expected Result:

A Chromium browser window opens, navigates to the specified website, prints the page title and closes.

🔐 9. Real-Time Example — Login Automation

Imagine your application has a login page. Playwright can automate entering credentials and verifying the logged-in page.

Open Login Page
→
Enter Username
→
Enter Password
→
Click Login
→
Verify Dashboard
test_login.py
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()
Security Tip:

Do not hard-code real production passwords or API secrets inside test source code. Use environment variables or a secure secret-management system.

🌐 10. Installing Specific Playwright Browsers

Playwright can install its supported browser binaries individually when you do not need every browser.

Chromium
playwright install chromium
Firefox
playwright install firefox
WebKit
playwright install webkit
Example:

If your team only needs Chromium-based automated tests, installing Chromium specifically can reduce unnecessary browser downloads.

🌍 11. Real-Time Example — Run the Same Test on Multiple Browsers

A major benefit of Playwright is the ability to automate Chromium, Firefox and WebKit through a consistent API.

Cross-Browser Example
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()
Real-world use case:

The same smoke test can be executed against multiple browser engines to detect browser-specific problems.

📊 12. Installation Commands by Device
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
🛠️ 13. Common Installation Problems

❌ 'python' is not recognized

Your Python executable may not be available through the system PATH.

Try:

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.

Fix
playwright install

❌ Linux dependency error

Some Linux systems require additional operating system libraries for browsers.

Fix
playwright install-deps

❌ Wrong Python Environment

The package might have been installed into a different Python environment.

Verify
python -m pip show playwright
✅ 14. Verify Your Installation

Run the following command to confirm that Playwright can launch a browser.

Verification Test
python -c "from playwright.sync_api import sync_playwright; print('Playwright is installed successfully')"
Expected Output:
$ Playwright is installed successfully
📁 15. Recommended Project Structure
Playwright Project
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
Professional Practice:

Keep application page objects, tests and test data separated as your automation project grows.

🏢 16. Real-Time Company Automation Workflow

Imagine a QA engineer joins a project where the application needs to be tested every day.

Developer Laptop
→
Create Python venv
→
Install Playwright
→
Install Browsers
→
Write Tests
→
Run Locally
→
CI/CD
requirements.txt
playwright
pytest

A new team member can then create the environment and install the same dependencies with:

Setup
python -m venv .venv

# Activate the environment

pip install -r requirements.txt

playwright install
⚙️ 17. Installation in CI/CD

In a CI/CD environment, the automation machine should install the Python dependencies and Playwright browsers before executing tests.

Generic CI Setup
python -m pip install --upgrade pip

pip install -r requirements.txt

playwright install

pytest
Important:

CI environments vary. Linux runners may also require browser operating-system dependencies, depending on the runner image and configuration.

📋 18. Playwright Installation Checklist
✓ Python installed
✓ pip available
✓ Project folder created
✓ Virtual environment created
✓ Virtual environment activated
✓ Playwright package installed
✓ Browser binaries installed
✓ pytest installed if required
✓ VS Code interpreter selected
✓ First test executed successfully
🎯 19. Final Perspective

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.

Python
+
Playwright
+
Browsers
+
pytest
=
Web Automation
Next Step:

After completing installation, the next practical lesson is to create your first Playwright framework using Page Object Model, pytest, reusable fixtures, screenshots and reporting.