Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

kubb-plugin-playwright

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.

Installation

With the Kubb CLI, once the plugin is listed in the Kubb registry:

npx kubb add ericlm/kubb-plugin-playwright

Or 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/test

Configuration

Keep 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.

Usage

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()
}

Documentation

Development

pnpm install
pnpm test       # generates the PetStore example, then runs vitest
pnpm typecheck
pnpm build

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages