Java Test Automation / Quiz

Object Design Inside the Page Layer

Review encapsulation, inheritance, composition, and polymorphism in a Java page-object design.

Difficulty
Medium
Format
Quiz
Points
150
Estimate
8 min

// MISSION BRIEF

Your Mission

The page layer works today but exposes locators, repeats browser mechanics, and inherits behavior it does not need. Review the class fragments as production code and choose boundaries that keep tests expressive and change local.

// FIRST CONTACT

Battle teaser

Review this page object: public class LoginPage { public By email = By.id("email"); public WebDriver driver; } Tests locate, type, and click through those public fields. Which refactor best applies encapsulation?

  1. AMake driver and locators private, inject the driver, and expose intent methods such as loginAs(user, password)
  2. BMove the public fields into each test class
  3. CReturn the raw driver from every page method
  4. DMake every field static so all tests share it
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

java-ooppage-object-modelencapsulationjava-testing