Selenium + Java · Lesson 36 of 44

0/44 done

Module 36: Test Data

36. Data-Driven Testing with External Files & POJO Models

16 minlesson

Your task

Implement generateEmailWithPrefix:

  1. Accept String prefix.
  2. Return prefix + "_" + System.currentTimeMillis() + "@targetqa.com".

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

Test Data POJO Pattern

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

    public UserCredentials(String email, String password) {
        this.email = email;
        this.password = password;
    }

    public String getEmail() { return email; }
    public String getPassword() { return password; }
}

// Random unique email generator:
public static String generateUniqueEmail() {
    return "test_" + System.currentTimeMillis() + "@targetqa.com";
}

Key Takeaways & Walkthrough Summary

Separating test logic from test data is essential for scalable automation. In this lesson, you will learn to manage static configurations via properties files, parse test data objects, and generate random dynamic data. Let's master test data!

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

Common Doubts & Lesson Q&A

Why avoid hardcoding user accounts in test scripts?

Hardcoded accounts lead to test collisions when running tests in parallel across multiple threads.

Ready? Solve the task in the editor

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

Java
Skip