Lesson 54 — Page Objects: One Page, One Class · Practical QA
LESSON VIEW
B-05 · ADVANCED · PRACTICAL QA

Lesson 54 — Page Objects: One Page, One Class

Objective: The pattern your whole framework is built from — one class per page, holding that page's facts and verbs.

⏱ ≈4 min full lesson · Converted from the B-05 module deck · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • The waiter analogy — A good waiter doesn't make you describe the kitchen.
  • HomePage, the real shape — Facts at the top (expectedTitle). The constructor takes the browser page.
  • Why tests love this — When the heading text changes, ONE fact in ONE class changes — and 40 tests keep passing, because they never knew the te…
  • Assertions live with the page too — expectLoaded() asserts the page's own facts — title, heading — from inside the object.
  • Plug & chug: sort the contents — Which belongs in HomePage, which in a test?

📖 Read

In ~4 minutes: the pattern your whole framework is built from — one class per page, holding that page's facts and verbs.

The waiter analogy: A good waiter doesn't make you describe the kitchen. They know the menu (facts) and take your order (actions). A Page Object is the waiter for one page: tests talk to it, never to the raw page.

HomePage, the real shape: Facts at the top (expectedTitle). The constructor takes the browser page. Then verbs: goto, expectLoaded. Facts and verbs — that's the whole anatomy (OOP track, O-02/O-03). Code: export class HomePage { | readonly expectedTitle = "Aoma AI Agency — …"; | constructor(page) { this.page = page; } | async goto() { await this.page.goto("/"); } | async expectLoaded() { /* asserts title + heading */ } | }

Why tests love this: When the heading text changes, ONE fact in ONE class changes — and 40 tests keep passing, because they never knew the text; they only knew expectLoaded(). Without Page Objects, the text lives in 40 places. Maintenance is the whole argument.

Assertions live with the page too: expectLoaded() asserts the page's own facts — title, heading — from inside the object. Rule of thumb: if a check is ABOUT the page's identity, it belongs to the page's class, not scattered across tests.

Plug & chug: sort the contents: Which belongs in HomePage, which in a test? “The pricing link points to /pricing” → page fact. “After login, show the dashboard” → test's story (B-08). Facts and single-page verbs live in the class; multi-step stories live in tests.

You can take a Page Object apart and say what every piece is for. Next: reading the results when tests run.