A community Kubb plugin that generates typed Playwright API request helpers from an OpenAPI specification. Each helper calls request.fetch and returns the native Playwright APIResponse, with a typed response.json().
Requires Node.js 22.22 or newer, Kubb 5.15 or newer, and @playwright/test 1.63 or newer.
With the Kubb CLI, once the plugin is listed in the Kubb registry:
npx kubb add ericlm/kubb-plugin-playwrightOr install it yourself, next to Kubb, the OpenAPI adapter, the TypeScript plugin, and Playwright:
pnpm add -D kubb @kubb/adapter-oas @kubb/plugin-ts kubb-plugin-playwright @playwright/test
# or
npm install --save-dev kubb @kubb/adapter-oas @kubb/plugin-ts kubb-plugin-playwright @playwright/testKeep pluginTs() in the plugins array. The default output puts types in src/gen/types and request helpers in src/gen/playwright.
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { defineConfig } from 'kubb/config'
import { pluginPlaywright } from 'kubb-plugin-playwright'
export default defineConfig({
input: './petStore.yaml',
adapter: adapterOas(),
output: { path: './src/gen' },
plugins: [pluginTs(), pluginPlaywright()],
})Then run npx kubb generate.
The call below uses the PetStore specification from this repository. Point the context baseURL at a running API. A standalone request context does not launch a browser.
import { request as playwright } from '@playwright/test'
import { pwGetPetById } from './src/gen/playwright'
const request = await playwright.newContext({ baseURL: 'http://127.0.0.1:3000' })
try {
const response = await pwGetPetById({
request,
path: { petId: '123' },
options: { timeout: 5_000 },
})
console.log(response.status(), await response.json())
} finally {
await request.dispose()
}- Overview and options on kubb.dev, built from the
docs/folder - PetStore HTTP tests, which start a local server and call the generated helpers through a real request context
pnpm install
pnpm test # generates the PetStore example, then runs vitest
pnpm typecheck
pnpm build