Bird
0
0

Analyze the following test class snippet:

medium📝 Predict Output Q4 of 15
Selenium Java - Page Object Model
Analyze the following test class snippet:
public class LoginTest {
  LoginPage loginPage = new LoginPage(driver);

  @Test
  public void testLogin() {
    boolean success = loginPage.login("user", "invalidPass");
    System.out.println(success ? "Login succeeded" : "Login failed");
  }
}

What will be printed if the login method returns false?
ALogin failed
BLogin succeeded
CCompilation error due to missing driver
DNo output because test fails silently
Step-by-Step Solution
Solution:
  1. Step 1: Understand the login method return

    The login method returns false indicating failure.
  2. Step 2: Analyze the print statement

    The ternary operator prints "Login failed" if success is false.
  3. Final Answer:

    Login failed -> Option A
  4. Quick Check:

    False login returns "Login failed" [OK]
Quick Trick: False login prints 'Login failed' [OK]
Common Mistakes:
MISTAKES
  • Assuming login returns true by default
  • Confusing output with exceptions
  • Ignoring ternary operator logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes