Main purpose
Use the runner to keep execution, setup, reporting, and debugging consistent across the whole suite.
A compact guide to the Playwright test runner, covering the features that make suites reliable, readable, and CI-ready.
Use the runner to keep execution, setup, reporting, and debugging consistent across the whole suite.
Put shared behavior in config or fixtures instead of repeating setup in each test.
Strong for parallel execution, CI pipelines, browser matrices, and typed fixtures.
Use this together with the Playwright CI/CD and Playwright API sheets.
Centralize retries, reporters, and browser projects in one place.
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
retries: 1,
reporter: 'html',
});
Projects let you run the same suite across browsers and device presets.
projects: [
{ name: 'chromium', use: { browserName: 'chromium' } },
{ name: 'firefox', use: { browserName: 'firefox' } },
]
Group related tests and keep setup scoped to where it belongs.
test.describe('login', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/login');
});
});
Fixtures keep setup reusable and make dependencies explicit.
const test = base.extend({
adminPage: async ({ browser }, use) => {
const page = await browser.newPage();
await use(page);
await page.close();
},
});
Parallelization is powerful, but it assumes tests are isolated and independent.
export default defineConfig({
fullyParallel: true,
workers: 4,
});
Use retries carefully for noise, not to hide real instability.
export default defineConfig({
retries: 2,
timeout: 30_000,
});
test.slow();
Pick reporters that help developers and CI consumers read failures quickly.
reporter: [
['html'],
['json', { outputFile: 'results.json' }],
]
Annotations help classify temporary or known execution behavior.
test.skip(); test.only(); test.fixme(); test.slow();
Use data-driven loops to cover variants without copy-pasting entire tests.
for (const role of ['admin', 'student']) {
test(`login as ${role}`, async ({ page }) => {
await page.goto(`/login?role=${role}`);
});
}
Use the runner’s built-in debugging features before inventing manual workarounds.
npx playwright test --debug npx playwright show-report npx playwright show-trace trace.zip