Record a web app's network responses once, replay them on every test run. Saisei (再生, "replay") makes flaky Playwright tests deterministic by freezing the one thing that keeps changing between runs: the network. It can also replay responses in a chosen order to reproduce race conditions on purpose, and warn you when the live API has drifted away from your recording.
Without Saisei: test passed 47/100 runs (flaky)
Saisei replay (recorded): test passed 100/100 runs
Saisei replay (reverse): failing order reproduced 100/100 runs
From npm run bench: a test that assumes /api/user arrives before /api/cart, against a demo shop whose APIs answer after random delays.
import { test, expect } from '@playwright/test';
import { saisei } from 'saisei';
test('checkout shows the price', async ({ page }) => {
// First run records real responses; later runs replay them.
const net = await saisei(page, 'recordings/checkout.json', { match: '/api/' });
await page.goto('https://shop.example.com/checkout');
await expect(page.locator('#price')).toHaveText('₹1,499');
await net.done();
});Re-record any time with SAISEI_MODE=record npx playwright test.
| What it does | |
|---|---|
| Record / replay | Saves matching responses (status, headers, body, latency) to a JSON file and serves them back with page.route. Binary bodies are stored as base64. Repeated calls to the same URL are served in recorded order. |
| Auto mode | saisei() records when the file is missing and replays when it exists. mode or SAISEI_MODE forces either. |
| Order control | order: 'recorded' | 'reverse' | 'shuffle' (with seed) releases concurrent responses in a fixed order. reverse turns a 1-in-N race into a failure you can debug every time. |
| Realistic timing | timing: 'recorded' waits as long as the real server did. |
| Drift detection | watchDrift() compares live responses with the recording by shape (fields and types, not values), e.g. $.price: removed, $.amount: added (string). |
| CLI | saisei show rec.json lists a recording; saisei diff old.json new.json reports drift and exits 1, for CI. |
| Miss reporting | Requests that aren't in the recording are listed in misses; onMiss: 'abort' blocks them. |
record(page, file, match?) // → save(): Promise<void>
replay(page, file, options?) // → { misses, stop() }
saisei(page, file, options?) // → { mode, misses, done() }
watchDrift(page, file, match?) // → { report(): Promise<DriftReport[]> }
diffRecordings(before, after) // compare two recordingsmatch is a substring, a RegExp, or a function of the URL. Replay options: timing, order, seed, stepMs, onMiss.
See docs/HOW-IT-WORKS.md.
npm install
npx playwright install chromium
npm test # 11 tests, against the demo Flaky Shop in fixtures/
npm run bench # the numbers above
npm run build # compiles to dist/ (library + CLI)MIT