import { faker } from '@faker-js/faker';

const randomUser = {
 firstName: faker.person.firstName(),
 lastName: faker.person.lastName(),
 email: faker.internet.email(),
 password: faker.internet.password(),
};

// Fill out a registration form
await page.fill('#first-name', randomUser.firstName);
await page.fill('#last-name', randomUser.lastName);
await page.fill('#email', randomUser.email);
await page.fill('#password', randomUser.password);
await page.click('#register-button');

// Assert successful registration
await expect(page.locator('.success-msg')).toHaveText('Registration successful!');

Use Case:

  • Testing forms, user flows, or APIs with unique data to avoid collisions.
  • Simulating edge cases like long names or special characters.

Why It’s Great:

  • Keeps your tests flexible and realistic.
  • Reduces the risk of hard-coded test data causing false positives.
  • Covers scenarios your static data might miss (e.g., generating 50+ users for load testing).
Verified Agency by DesignRush badge
Top Clutch Companies Romania 2022 badge
Tip NodeJS Developers Timisoara 2023 badge
Top IT Services Companies Education Romania 2023 badge
Top Software Developer Timisoara 2023 badge