← All Posts

How to Set Up Playwright from Scratch in 2025: A Complete Guide

2/25/2025

Playwright has become the default choice for E2E testing in 2025. If you're starting from scratch, this guide will get you from zero to a production-ready test setup in under an hour.

Installation

npm init playwright@latest
# Choose TypeScript, tests folder, GitHub Actions, install browsers

This gives you a working setup with example tests, a config file, and optionally a GitHub Actions workflow.

Project structure

tests/
  auth/
    login.spec.ts
    signup.spec.ts
  checkout/
    cart.spec.ts
    payment.spec.ts
pages/
  login.page.ts
  checkout.page.ts
fixtures/
  index.ts
playwright.config.ts

Your first test

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

test('homepage loads and shows title', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveTitle(/My App/);
  await expect(
    page.getByRole('heading', { name: 'Welcome' })
  ).toBeVisible();
});

Configuration essentials

Key settings in playwright.config.ts:

  • baseURL: Set this so tests use relative URLs
  • retries: Set to 1-2 in CI, 0 locally
  • workers: Use all available cores locally, shard in CI
  • reporter: Use html locally and junit in CI
  • use.trace: Set to 'on-first-retry' for debugging

Next steps

  • Add page objects for complex pages (see my POM guide)
  • Set up CI integration (see my CI/CD guide)
  • Add API testing alongside E2E tests
  • Set up visual regression testing

Need help setting up Playwright for your team? Get in touch. We do this for engineering teams every week.

Need Help Implementing This?

We help engineering teams set up test automation, CI/CD, and quality infrastructure.