Skip to content

Playwright

Playwright is the best fit when you need chaos from the first page load. The adapter registers Chaos Maker as an init script before page.goto().

Terminal window
npm install @chaos-maker/core @chaos-maker/playwright
import { test, expect } from '@playwright/test';
import { injectChaos, getChaosLog, getChaosSeed } from '@chaos-maker/playwright';
test('shows error state when the API fails', async ({ page }) => {
await injectChaos(page, {
seed: 42,
network: {
failures: [{ urlPattern: '/api/orders', statusCode: 503, probability: 1 }],
},
});
await page.goto('/orders');
await expect(page.locator('[data-testid="error-state"]')).toBeVisible();
const log = await getChaosLog(page);
expect(log.some((event) => event.type === 'network:failure' && event.applied)).toBe(true);
console.info('Chaos seed:', await getChaosSeed(page));
});

Pass testInfo with tracing enabled to annotate Playwright traces and attach the chaos log.

await injectChaos(page, config, { tracing: true, testInfo });

The fixture entry point can also wire tracing automatically for suites that prefer shared setup.