Playwright Test Runner
Playwright Test is more than a browser library — its runner handles projects, fixtures, parallelism and reporting.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
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#
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' });
// });
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#
- Retries and traces are enabled only in CI.
- The setup project saves the signed-in state.
- Browser projects depend on setup and reuse the state.
- 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#
Slow and flaky. Use storageState or API login.
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
npx playwright test --project=mobile
Mini quiz#
What does storageState save?
Want more? Practise all Automation Testing MCQs · Automation Testing interview questions
My notes#
Saved in this browser.