</>

Technology

Playwright

Difficulty

Beginner

Interview Question

How do you install Playwright?

Answer

Installing Playwright

Method 1: Interactive Setup (Recommended for new projects)

Bash
npm init playwright@latest

This command:

  1. āœ“Asks which language (TypeScript or JavaScript)
  2. āœ“Asks where to put tests (default: tests/)
  3. āœ“Adds a GitHub Actions workflow (optional)
  4. āœ“Installs @playwright/test package
  5. āœ“Creates playwright.config.ts
  6. āœ“Creates a sample test file
  7. āœ“Downloads Chromium, Firefox, and WebKit browser binaries

Method 2: Manual Install into Existing Project

Bash
# Install the package
npm install --save-dev @playwright/test

# Install browser binaries
npx playwright install

# Optional: install only specific browsers
npx playwright install chromium

Method 3: Install with Dependencies (for Linux CI)

Bash
npx playwright install --with-deps chromium

Installs the browser AND all OS-level dependencies (fonts, codecs) needed on Ubuntu/Debian.

What Gets Created

CODE
my-project/
ā”œā”€ā”€ tests/
│   └── example.spec.ts     # Sample test
ā”œā”€ā”€ playwright.config.ts     # Configuration file
ā”œā”€ā”€ package.json
└── node_modules/
    └── @playwright/test/

Verify Installation

Bash
npx playwright --version
# Shows: Version 1.x.x

npx playwright test
# Runs all tests in the tests/ folder

Running Your First Test

The generated sample test at tests/example.spec.ts:

TypeScript
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  await expect(page).toHaveTitle(/Playwright/);
});
Bash
npx playwright test                  # Run all tests
npx playwright test --headed         # Run with browser visible
npx playwright show-report           # Open HTML report

Follow AutomateQA

Related Topics