8 / 57 · 26 Testing Like a Senior · Authentication and Navigation Patterns← prev⊞ allnext →☰ Read as one page
2.3Page Objects as Behaviors, Not Selectors
Anti-Pattern: Page objects are thin wrappers around selectors —
loginPage.emailInput,loginPage.passwordInput,loginPage.submitButton. Tests still script low-level interactions.
Pattern: Page objects expose behaviors —
loginPage.loginAs(user),dashboardPage.createReport(params). Tests describe intent, not clicks.
The three-layer architecture that scales:
| Layer | Responsibility | Example |
|---|---|---|
| Test Layer | Describes what is being verified | expect(dashboard.reportCount).toBe(5) |
| Service Layer | Orchestrates multi-page workflows | app.createUserWithOrders(3) |
| Page Object Layer | Encapsulates single-page interactions | orderPage.fillShipping(address) |
When a UI element changes, only the page object changes. When a workflow changes, only the service layer changes. Tests remain stable because they describe intent, not implementation.