Next.js & Playwright / Cypress
The problem
Random data in E2E tests is brittle: a DNI or an IBAN generated on the fly can clash with validations, or make a test fail once in a thousand runs for no apparent reason.
The fix: a fixed seed per test
Each test uses its own seed (for example, the test name). Same seed + same parameters ⇒ always the same data, so the test is reproducible and its assertions can use concrete values.
Playwright
tests/alta-cliente.spec.ts
import { test, expect } from "@playwright/test";
async function fetchDni(seed: string) {
const res = await fetch(
"https://datamockseed.firstflip.es/api/v1/es/document?sub=dni&count=1&seed=" + seed,
);
const { data } = await res.json();
return data[0].documento as string;
}
test("the sign-up form accepts a fake DNI", async ({ page }) => {
const dni = await fetchDni("signup-e2e"); // same seed => same DNI on every run
await page.goto("/signup");
await page.getByLabel("DNI").fill(dni);
await page.getByRole("button", { name: "Continue" }).click();
await expect(page.getByText("Valid DNI")).toBeVisible();
});Cypress
cypress/e2e/alta-cliente.cy.js
Cypress.Commands.add("fixtureDni", (seed) => {
return cy
.request(
`https://datamockseed.firstflip.es/api/v1/es/document?sub=dni&count=1&seed=${seed}`,
)
.its("body.data.0.documento");
});
it("accepts a fake DNI", () => {
cy.fixtureDni("signup-e2e").then((dni) => {
cy.visit("/signup");
cy.findByLabelText("DNI").type(dni);
cy.findByRole("button", { name: "Continue" }).click();
cy.findByText("Valid DNI").should("be.visible");
});
});Complete fixture datasets
For a fixture with several consistent rows (name + DNI + email), use POST /v1/es/bulk
with the test's seed instead of chaining individual requests.