2. Conditional Logic for Test Assertions

Conditional Statements in Test Automation

In automated testing, conditional logic verifies test results:
if (actualTitle.equals(expectedTitle)) {
    System.out.println("TEST PASSED: Page title matches");
} else {
    System.out.println("TEST FAILED: Title mismatch");
}

> Critical Rule: Always use .equals() or .equalsIgnoreCase() to compare String values in Java. Using == compares memory addresses, not characters!

Task

  • Write an `if-else` statement that compares `actualTitle` with `expectedTitle`:
  • If they are equal using `.equals()`, print `"PASS"`.
  • Otherwise, print `"FAIL"`.
💡Common doubts
Did you like the problem?
Lesson 2 of 18
Java
Loading code editor…
Next