Playwright + Java · Lesson 29 of 38

0/38 done

Module 29: Test Data

29. Data-Driven Testing & External Test Data Providers

16 minlesson

Your task

Create a method generateRandomUsername():

  1. Return "user_" + System.currentTimeMillis() + "@test.com".

Write it in the editor, then press Check answer (Ctrl + Enter).

Java POJO for Test Data

java
public class UserCredentials {
    private String email;
    private String password;
    private String expectedRole;

    // Getters and Setters
    public String getEmail() { return email; }
    public String getPassword() { return password; }
    public String getExpectedRole() { return expectedRole; }
}

// Data provider streaming multiple scenarios:
List<UserCredentials> testUsers = Arrays.asList(
    new UserCredentials("admin@targetqa.com", "adminPass", "ADMIN"),
    new UserCredentials("user@targetqa.com", "userPass", "STANDARD")
);

Key Takeaways & Walkthrough Summary

Hardcoded test data limits coverage. In this lesson, you will master Data-Driven Testing. You will learn to parse JSON and CSV data into strongly typed Java POJOs and drive automated tests with multiple user scenarios and roles. Let's master test data!

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

Common Doubts & Lesson Q&A

Why use random usernames in registration tests?

Static usernames fail on subsequent test runs due to uniqueness constraints (e.g. 'Email already registered'). Dynamic timestamps prevent collisions.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Java
Skip