Answer
Installing Playwright
Method 1: Interactive Setup (Recommended for new projects)
Bash
npm init playwright@latest
This command:
- āAsks which language (TypeScript or JavaScript)
- āAsks where to put tests (default:
tests/) - āAdds a GitHub Actions workflow (optional)
- āInstalls
@playwright/testpackage - āCreates
playwright.config.ts - āCreates a sample test file
- ā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
