For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /docs/playwright/index.md.

Playwright

@decoyhq/playwright routes your browser's API calls to decoy, gives each test its own Session, and exposes the Control API as a fixture.

npm
pnpm
yarn
bun
npm install -D @decoyhq/cli @decoyhq/playwright
playwright.config.ts
import type { DecoyTestOptions } from '@decoyhq/playwright'
import { defineConfig } from '@playwright/test'

export default defineConfig<DecoyTestOptions>({
  globalSetup: './global-setup.ts',
  use: {
    baseURL: 'http://127.0.0.1:4173',

    decoyOptions: {
      command: 'decoy serve --config mocks/decoy.yaml',
      urls: '**/api/**', // browser requests sent to Decoy
      collection: 'happy-path', // each test's Session starts here
    },
  },
})
global-setup.ts
export { setup as default } from '@decoyhq/playwright'
tests/fixtures.ts
import { createDecoyFixtures, type DecoyFixtures } from '@decoyhq/playwright'
import { test as base } from '@playwright/test'

export const test = base.extend<DecoyFixtures>(createDecoyFixtures())
export { expect } from '@playwright/test'

Next, switch responses in a test. For a page that opens a socket, bridge browser WebSockets.

Options (use.decoyOptions)

optiondefaultmeaning
urlhttp://127.0.0.1:8080where Decoy serves
commanddecoy serveshell command setup runs when Decoy isn't up
cwdthe config file's directoryworking directory for command
reuseExistingServertrue locally, false in CIreuse a Decoy already answering health
timeout60000ms setup waits for health
urlsnoneglob/RegExp (or list) of browser requests to route
webSocketUrlsnoneglob/RegExp (or list) of page WebSockets to bridge
collectionDecoy's defaultCollection each test's Session starts on

Decoy is off for projects without decoyOptions. setup starts one Decoy per distinct url: projects that share a url share a Decoy, and each other url gets its own command. command runs with node_modules/.bin (from cwd up) on PATH. Teardown sends SIGTERM and, if Decoy hasn't exited after 8s, SIGKILL (Windows: taskkill /T /F). Projects that share a url must agree on command, cwd, reuseExistingServer and timeout, or setup fails.

The runnable version of all this is examples/playwright-ts-e2e.