LESSON VIEW
PQA-10 · LEVEL 3 AUTOMATION & RELEASE · PRACTICAL QA

Page Objects and a Framework That Lasts

Objective: Restructure a working suite with the Page Object Model — one class per page owning its selectors and actions — so a markup change costs one edit, and prove the refactor changed nothing by re-running both builds.

⏱ ≈3 h full lesson · Includes the real test-run video · English edition — Español · العربية · বাংলা in translation

🧽 The practice business: FreshNest Home Cleaning — a fictional local cleaning company (owner: Maya Torres) invented for this course. Every example and exercise uses FreshNest, so you learn on a complete, realistic business without ever touching a real one.

2 of 11 modes explored

Ways to learn this lesson

Tap a title to open that way of learning. Use as many as you need — then take the lesson quiz below.

📖Read
The full lesson, in order
~30 min›

Your PQA-09 tests work — and they contain a time bomb. The selector for the estimate is typed inside a test. Put it in six tests, and the day the page renames that element, six tests break and you edit six files to fix a change that has nothing to do with behaviour. The Page Object Model removes the duplication of knowledge: everything the suite knows about where things are on a page lives in that page's class. Tests say what a user does and what should be true; the class knows where to click.

The framework around it is deliberately small: a config (PQA-09), page objects under pages/, specs under tests/ named by what they verify, and generated evidence under test-results/. Three rules keep it healthy. Tests never contain a raw selector. A page class exposes intentions — choose('deep', '2'), expectEstimate('$210') — not element plumbing. And every test title carries its test-case ID, so a failure reads as a case ID that traces straight into the matrix.

Resist the bigger-framework temptation. No factories, wrappers, or utility layers until a real repetition hurts. Over-built frameworks are why teams abandon suites; this one has exactly three ideas, and you can hold all of them in your head while reading any test in it.

⚡Key Points
The whole lesson in 5 bullets
~5 min›
  • POM: one class per page owns that page's selectors and actions.
  • Tests state intentions; the class knows where things are.
  • A markup change should cost exactly one edit — in the page class.
  • Keep the framework small: config, page objects, IDs on tests.
  • Prove a refactor by identical verdicts on both builds.
🪜Worked Example
Watch one task done step by step
~12 min›

The course lab project, restructured. Watch the run video in the Visual tab: TC-FN-PRC-001 executing green against the fixed build.

The structure

playwright-project/ → playwright.config.ts · pages/QuotePage.ts · tests/pricing.spec.ts (PRC-001…003) · tests/validation.spec.ts (VAL-001…003) · test-results/ (generated evidence).

The page object (QuotePage)

Locators declared once: service, beds, estimate, name, phone, dateWindow, errors, success, submitButton. Methods: goto(), choose(service, beds), expectEstimate(text), fillDetails(...), submit().

The test, rewritten

const quote = new QuotePage(page); await quote.goto(); await quote.choose('deep', '2'); await quote.expectEstimate('$210'); — it now reads like the test case it came from.

Verdict on the buggy build

Identical to before the refactor: 3 failed (PRC-001, VAL-001, VAL-002), 3 passed.

Verdict on the fixed build

6 passed. Same suite, no test edits — only SITE_URL changed.

The refactor proof

Same verdicts on both builds before and after restructuring = the shape changed, the meaning didn't. That invariance is how you know a refactor is safe.

🗺️Visual Map
The idea as a diagram
~6 min›
One place knows the pageTests state intentionschoose() · expectEstimate()Page class owns selectorsQuotePage.ts — one line to fixConfig steers the buildSITE_URL picks buggy / fixedMarkup changesOne edit absorbs itA test failsA case ID names the failureIdentical verdicts = a safe refactornamescallsdrivesCase IDTestPage objectThe page

One map of the lesson: tests talk to page objects, page objects talk to the page, and config steers all of it at a build.

🧪Hands-On Lab
Do it yourself, then reveal the key
~20 min›

Where does each fragment belong in the project?

1. baseURL: process.env.SITE_URL || 'http://localhost:8931'

2. this.estimate = page.locator('#estimate-output')

3. test('TC-FN-PRC-001: Deep clean, 2 bedrooms, estimates $210', …)

4. await quote.choose('deep', '2')

5. video.webm + test-failed-1.png from the last run

🎧Listen
Hear it narrated in your language
~4 min›

The Page Object Model is one idea. Everything your suite knows about where things are on a page lives in one class for that page. The estimate selector appears exactly once, inside QuotePage. Your tests stop speaking in selectors and start speaking in intentions: choose Deep and two bedrooms, expect the estimate to say two hundred ten dollars. When the page renames an element, and one day it will, you edit one line instead of six files. And you prove the restructure was safe the only honest way: the suite's verdicts on the buggy build and the fixed build are identical before and after. Shape changed. Meaning did not.

🃏Flashcards
Key terms, flip to recall
~6 min›
Page Object Model
Tap the card to flip it

One class per page owning that page's selectors and actions.

1/5
🎭Scenario
A story decision — you be the owner
~7 min›

A teammate proposes adding a BasePage, a ComponentFactory, and a waits utility layer before the suite has ten tests. You…

🗣️Teach-Back
Explain it in your own words
~10 min›

Explain POM to a friend using a restaurant: the menu, the waiter, and the kitchen — who is the test, who is the page object, and what is selector rot in this analogy?

Now check yourself honestly:

⚖️Before / After
Weak way vs strong way, side by side
~6 min›
Before POMAfter POM
A rename breaks six files; fixes take an afternoon.

'#estimate-output' typed inside six tests.

A rename costs one line; verdicts unchanged on both builds.

'#estimate-output' declared once in QuotePage.

📋Job Aid
A checklist to use at work
~3 min›

📝 Lesson Quiz — Check Yourself

1. The estimate element's id changes from #estimate-output to #estimate-value. With POM, what do you edit?

2. Why do test titles carry TC-FN IDs?

3. One test in your suite fails intermittently on the same build. First move?

Score: 0 / 3
🎬 Watch It Done

Watch it done — TC-FN-PRC-001 executing against the fixed build: the browser selects Deep + 2 bedrooms and the estimate asserts $210. Recorded from the course lab's real Playwright run.