Playwright + JS · Lesson 10 of 35

0/35 done

Module 10: Practice Project — Test Data Management Utility

10. Capstone Project: Test Data Management Utility

18 minlesson

Try it yourself

Implement generateRandomUser:

  1. Accept prefix string defaulting to "user".
  2. Generate timestamp with Date.now().
  3. Return { username: ${prefix}_${timestamp}, email: ${prefix}_${timestamp}@targetqa.com, role: "tester" }.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Capstone: Test Data Management Utility

In real-world automation, hardcoding static emails leads to collision errors in parallel test runs. We build a utility that dynamically generates isolated test data payloads:

javascript
export class TestDataManager {
  static generateRandomUser(prefix = "user") {
    const timestamp = Date.now();
    return {
      username: `${prefix}_${timestamp}`,
      email: `${prefix}_${timestamp}@targetqa.com`,
      role: "tester",
      createdAt: new Date().toISOString()
    };
  }

  static async loadUserByRole(role) {
    if (!role) throw new Error("Role parameter is required");
    return { role, permissions: ["read", "write"] };
  }
}

Key Takeaways & Walkthrough Summary

Congratulations on completing the JavaScript fundamentals! In this capstone project, we will build a Test Data Management Utility. You will combine classes, random data generation, error handling, and async functions to create a reusable test data provider ready for Playwright. Let's build it!

Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why use timestamp-based dynamic test emails?

When tests run repeatedly or in parallel, static emails like test@example.com fail on 'Account already exists' validation. Timestamps guarantee unique credentials.

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

JavaScript
Skip