SA
SDET QA

Installing Playwright

Learn how to install Playwright and set up your testing environment.

Prerequisites

  • Node.js version 16 or higher
  • npm or yarn package manager

Installation Steps

1. Initialize a New Project

Create a new directory and initialize npm:

bash
mkdir my-playwright-tests
cd my-playwright-tests
npm init -y

2. Install Playwright

Install Playwright with test runner:

bash
npm init playwright@latest

This command will:

  • Install Playwright and its dependencies
  • Set up browser binaries (Chromium, Firefox, WebKit)
  • Create a playwright.config.ts configuration file
  • Add example test files

3. Verify Installation

Run the example tests to verify everything is working:

bash
npx playwright test

Configuration

The playwright.config.ts file contains all your test configuration:

typescript
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  use: {
    baseURL: 'http://127.0.0.1:3000',
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },
    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },
  ],
});