← Back to library
Playwrightfixturesintermediatev1.20+

Generate random test data inline

Create unique email and username values per run to prevent conflicts in a shared test database.

1test('registers a new user with unique credentials', async ({ page }) => {
2  // Generate a short unique suffix — avoids conflicts in a shared DB
3  const uid = Math.random().toString(36).slice(2, 10);
4  const email = `qa+${uid}@example.com`;
5  const username = `user_${uid}`;
6
7  await page.goto('/register');
8  await page.getByLabel('Username').fill(username);
9  await page.getByLabel('Email').fill(email);
10  await page.getByLabel('Password').fill('Str0ng!Pass');
11  await page.getByRole('button', { name: 'Create account' }).click();
12
13  await expect(page.getByText(`Welcome, ${username}`)).toBeVisible();
14});
#random#test data#unique#faker#Math.random