DEV Community

TestDino
TestDino

Posted on

Mistake 4/14: Same data breaks Playwright group tests

Running tests together? Same "test@test.com" makes workers fight over one user. Quiet fails everywhere. I reviewed a test suite last week where hardcoded data completely killed their pipeline stability. Worker 1 passes, Workers 2-5 throw "email already exists."

BEFORE : Tests fight each other

test('register new user', async ({ page }) => {
  await page.getByLabel('Email').fill('test@test.com'); 
  // Worker 1: passes. Workers 2-5: fail instantly
});
Enter fullscreen mode Exit fullscreen mode

AFTER : The Factory + JSON Combo

Keep your hacks and limits in a static JSON file. Use a Faker factory for everything else. Zero collisions!

import { faker } from '@faker-js/faker';
import invalidInputs from './invalid-inputs.json';

// 1. Factory function for dynamic, unique runs
export function createTestUser() {
  return {
    email: `test-${Date.now()}-${faker.string.alphanumeric(5)}@test.com`,
    password: faker.internet.password({ length: 12 })
  };
}

test('happy path: zero collisions', async ({ page }) => {
  const user = createTestUser();
  await page.getByLabel('Email').fill(user.email);
  await page.getByLabel('Password').fill(user.password);
});

// 2. Static JSON data for deterministic edge cases
test('reject sql injection in name field', async ({ page }) => {
  // invalidInputs.sqlInjection[0] = "' OR 1=1 --"
  await page.getByLabel('Name').fill(invalidInputs.sqlInjection[0]);
  await expect(page.getByText('Invalid input')).toBeVisible(); 
});

Enter fullscreen mode Exit fullscreen mode

Fixed data for hacks. Faker for everything else.

What's your test data strategy? Comments below.

Top comments (0)