Automation Testing · Playwright

Playwright Test Runner

Playwright Test is more than a browser library — its runner handles projects, fixtures, parallelism and reporting.

Intermediate 5 min Lesson 11 of 24
0/24 in Automation Testing
On this page · 5 min · Intermediate

Learning objectives#

  • Configure playwright.config.ts
  • Run across browsers and devices
  • Reuse login with storageState
  • Create custom fixtures

Explanation#

playwright.config.ts sets baseURL, timeouts, retries, reporters and projects (Chromium, Firefox, WebKit, mobile devices).

A setup project can log in once and save storageState; other projects reuse it, so tests start signed in.

Fixtures provide ready-made objects (page objects, API clients) to tests via parameters.

Tests run in parallel workers; retries and traces help diagnose intermittent failures.

Code example: Config with login setup#

TypeScriptplaywright.config.ts Illustrative
import { defineConfig, devices } from '@playwright/test';


export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  retries: process.env.CI ? 2 : 0,
  reporter: [['html'], ['junit', { outputFile: 'results/junit.xml' }]],
  use: { baseURL: process.env.BASE_URL ?? 'http://localhost:5173', trace: 'on-first-retry' },
  projects: [
    { name: 'setup', testMatch: /auth\.setup\.ts/ },
    { name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: '.auth/user.json' }, dependencies: ['setup'] },
    { name: 'mobile', use: { ...devices['Pixel 7'], storageState: '.auth/user.json' }, dependencies: ['setup'] },
  ],
});


// tests/auth.setup.ts
// setup('log in', async ({ page }) => {
//   await page.goto('/login'); …fill and submit…
//   await page.context().storageState({ path: '.auth/user.json' });
// });
Expected output
The setup project logs in once; Chromium and Pixel 7 tests run in parallel already signed in, with HTML and JUnit reports.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. Retries and traces are enabled only in CI.
  2. The setup project saves the signed-in state.
  3. Browser projects depend on setup and reuse the state.
  4. Two reporters serve humans (HTML) and CI (JUnit).

Real-world use case#

A 200-test suite logs in once instead of 200 times, saving several minutes per run.

Common mistakes#

Logging in through the UI in every test

Slow and flaky. Use storageState or API login.

Committing .auth files

They contain session cookies. Add them to .gitignore.

Best practices#

  • Setup project + storageState
  • Projects for browsers and devices
  • Fixtures for page objects
  • Traces on first retry

Remember this#

Config = baseURL, projects, retries, reporters.

Log in once with storageState.

Fixtures inject helpers into tests.

Practice exercise#

Your task: Run only the mobile project.

Show solution
Shell Illustrative
npx playwright test --project=mobile

Mini quiz#

Playwright Test Runner quizMultiple choice Question 1 of 1

What does storageState save?

Score so far: 0/0

Want more? Practise all Automation Testing MCQs · Automation Testing interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.