Playwright addon

Realistic fixtures for Playwright

The fakeData fixture pulls realistic synthetic data straight into your tests — seeded, reproducible, and typed end to end. One line per record, zero client wiring.

Install

Add the package as a dev dependency alongside @playwright/test. Requires Node 18+ for global fetch.

terminal
pnpm add -D @przeslijmi/real-fake-data-playwright

Quick start

Point the fixture at a Real Fake Data API instance with test.use, then pull data inside any test. test and expect are the standard Playwright exports, extended with the fakeData fixture — use them exactly as you would @playwright/test.

example.spec.ts
import { test, expect } from '@przeslijmi/real-fake-data-playwright';

test.use({ realFakeData: { baseUrl: 'https://realfakedata-api.onrender.com' } });

test('registers a new customer', async ({ page, fakeData }) => {
  const person = await fakeData.plPerson({ sex: 'f' });

  await page.goto('/signup');
  await page.getByLabel('First name').fill(person.name);
  await page.getByLabel('Surname').fill(person.surname);
  await page.getByLabel('PESEL').fill(person.pesel);
  await page.getByRole('button', { name: 'Create account' }).click();

  await expect(page.getByText(person.surname)).toBeVisible();
});

Seeded and reproducible

Each test derives a stable seed from its title, so a failing test replays the exact same data on the next run — no flakiness, trivial repro. Within a test, the Nth call uses seed + N, keeping calls distinct yet deterministic. Set seed explicitly only when you want to pin a file to a known fixed dataset.

playwright.config.ts
test.use({ realFakeData: { baseUrl, seed: 42 } }); // pin this file to a fixed dataset

Generators

Each generator exposes a singular method returning one record and a plural taking count as its first argument and returning an array. Method names are locale-prefixed (plPesel, plCompany, …); locale-agnostic generators (email, lorem) carry no prefix. Every method accepts optional constraints.

SingularPluralReturnsCommon options
plPeselplPesels{ value, birthDate, sex }sex, atAge, olderThan, …, invalid
plPersonplPeople{ name, surname, initials, birthDate, pesel }same as plPesel
plAddressplAddresses{ buildingNumber, postalCode, cityName, … }teryt
plNipplNips{ value, digits }format, invalid
plIbanplIbans{ value, electronicFormat, bankCode, bankName }format, bankCode, bankName, invalid
plRegonplRegons{ value, variant }variant, invalid
plCompanyplCompanies{ name, legalForm, nip, regon }strategy, legalForm, …, invalid
plVehicleRegistrationplVehicleRegistrations{ value, prefix, individualPart, type, … }type, voivodeship, …
emailemails{ value, localPart, domain, pattern, plusTag }domain, pattern, …
loremlorems{ value, words, chars, bytes, paragraphs }bytes, chars, words, paragraphs

Testing your validators

Every checksum generator accepts invalid: true to produce a value with a deliberately wrong check digit — the rest stays well-formed — so you can assert that your own validators reject bad input.

validator.spec.ts
const bad = await fakeData.plNip({ invalid: true });
await expect(submitNip(bad.value)).rejects.toThrow('invalid checksum');

Error handling

A non-2xx API response throws a RealFakeDataError carrying status (HTTP code), code (the API’s machine error code), and details (per-field validation messages).

error-handling.ts
import { RealFakeDataError } from '@przeslijmi/real-fake-data-playwright';

try {
  await fakeData.plAddress({ teryt: 'not-digits' });
} catch (error) {
  if (error instanceof RealFakeDataError) {
    console.log(error.status, error.code, error.details);
  }
}

Ready to drop it into your suite?

Grab an API key, point the fixture at it, and start pulling realistic data into your tests today.