j0ny3ngliSh

If you're writing Playwright API tests manually from an OpenAPI/Swagger spec, you're doing work that should be automated.

Every endpoint in your spec already tells you:

  • What the request looks like (path, method, parameters, body schema)
  • What responses to expect (200, 401, 404, 422...)
  • What fields are required
  • What security is needed

That's not documentation — it's a test plan. You're just not running it yet.

What I built

I got tired of the boilerplate loop: read spec → write happy path → add 401 test → add missing-field test → repeat for 40 endpoints. So I built a tool that does it for you.

swagger-to-playwright.vercel.app takes your OpenAPI 3.x spec (YAML or JSON) and generates a ready-to-run Playwright .spec.ts file.

For each endpoint, it produces four tests:

1. Happy path — calls the endpoint with valid data, asserts 2xx response and key fields in the body.

2. Auth check — if your spec declares a security scheme, it calls without a token and asserts 401. Only generated when the spec actually says authentication is required — no false positives.

3. Input validation — sends a request with missing required fields (or wrong types, invalid enums) and asserts 422. Reads directly from your schema's required array and field types.

4. Contract validation — if there's a path parameter, it calls with an invalid value and asserts 404.

What the output looks like

Here's what you get for a POST /users endpoint with email and password required:

import { test, expect } from '@playwright/test';

test.describe('POST /users', () => {
  test('happy path — creates user successfully', async ({ request }) => {
    const res = await request.post('/users', {
      data: { email: '[email protected]', password: 'password123' }
    });
    expect(res.status()).toBe(201);
    const body = await res.json();
    expect(body).toHaveProperty('id');
  });

  test('auth — 401 without token', async ({ request }) => {
    const res = await request.post('/users', {
      headers: { Authorization: '' },
      data: { email: '[email protected]', password: 'password123' }
    });
    expect(res.status()).toBe(401);
  });

  test('validation — 422 on missing required fields', async ({ request }) => {
    const res = await request.post('/users', {
      data: {}
    });
    expect(res.status()).toBe(422);
  });
});

Enter fullscreen mode Exit fullscreen mode

Paste this into your Playwright project, set baseURL in playwright.config.ts, and run it.

What it doesn't do (intentionally)

  • It doesn't test business logic — that's yours to write
  • It doesn't mock — it hits a real API
  • It doesn't replace contract testing tools like Dredd or Pact — it's a starting point, not a full solution

The goal is to take you from zero to running API tests in 5 minutes, not to replace your entire test strategy.

Who it's for

Teams that:

  • Already use TypeScript + Playwright for E2E tests and want API tests in the same framework
  • Have an OpenAPI spec and want to bootstrap test coverage fast
  • Are tired of writing the same auth/validation boilerplate for every endpoint

If you're already invested in pytest/requests or another API testing tool, this probably isn't for you — switching isn't worth it just for this.

Try it

swagger-to-playwright.vercel.app — free, no login, no install.

I'm actively building on this. Full-spec ZIP download (generate all endpoints at once) is coming next. If you try it and something's missing or broken, drop a comment — genuine feedback makes it better.


Source on GitHub. Built with Vite + TypeScript, deployed on Vercel.