Bird
0
0

What is wrong with this test class snippet?

medium📝 Debug Q7 of 15
Selenium Java - Page Object Model
What is wrong with this test class snippet?
public class DashboardTest {
  DashboardPage dashboardPage = new DashboardPage(driver);

  @Test
  public void testLoadDashboard() {
    dashboardPage.load();
  }

  @AfterMethod
  public void tearDown() {
    driver.quit();
  }
}
AtearDown should be annotated with @BeforeMethod
Bdriver is not initialized before use
Cload method should return boolean
DDashboardPage should be instantiated inside test method
Step-by-Step Solution
Solution:
  1. Step 1: Check driver usage

    driver is used to create DashboardPage but no initialization shown.
  2. Step 2: Consequence of uninitialized driver

    Using uninitialized driver causes NullPointerException at runtime.
  3. Final Answer:

    driver is not initialized before use -> Option B
  4. Quick Check:

    Uninitialized driver = runtime error [OK]
Quick Trick: Always initialize WebDriver before page objects [OK]
Common Mistakes:
  • Assuming driver is auto-initialized
  • Misplacing @AfterMethod annotation
  • Expecting method return type to cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes