Generate Playwright API tests from OpenAPI or Swagger

Use the API contract you already maintain to create a practical starting point for API testing. Paste an OpenAPI or Swagger document, choose an endpoint, and get a ready-to-run TypeScript test. Pasted and uploaded specs stay in the browser, and no account is required.

1. Load your API definition

Upload YAML or JSON, paste the document, or fetch a public spec URL. OpenAPI 3.x and Swagger definitions both work.

2. Select an endpoint

Review the generated request for one operation, then copy a .spec.ts file or download every detected endpoint as a ZIP.

3. Make it your own

Set environment-specific values and add business scenarios around the generated contract tests in your existing Playwright project.

What the Playwright API test generator uses

Each output starts from details declared in the specification: the HTTP method and server URL, path and query parameters, request-body schema, documented success responses, and operation security. This creates a useful baseline without pretending the specification knows your product’s business rules.

Example generated Playwright API test

test('lists available pets', async ({ request }) => {
  const response = await request.get('/pets', {
    params: { status: 'available' },
  });

  expect(response.status()).toBe(200);
  expect(await response.json()).toHaveProperty('pets');
});

Frequently asked questions

Can Playwright test APIs?

Yes. Playwright’s request fixture can send HTTP requests independently of browser UI tests. Generated files use @playwright/test and are designed to be placed in a normal Playwright suite.

Does this work with Swagger?

Yes. Swagger is the earlier name commonly used for API definitions; the generator accepts Swagger documents as well as OpenAPI YAML and JSON files.

Will the tests run without changes?

The generated structure is runnable, but real APIs often need environment URLs, credentials, and test data. Treat it as an accurate contract-testing baseline, then add the product-specific setup your API requires.

Is my API specification private?

Specs pasted or uploaded into the generator are handled in the browser. Fetching a URL uses a proxy only to retrieve that URL; the app does not require an account or save the document.