LESSON VIEW
LAB-0 · AUTOMATION PRACTICE LAB · PRACTICAL QA

OOP Primer for Testers

Objective: Read any Page Object fluently — class, object, property, constructor, method — and explain why this framework builds pages from parts (composition) instead of family trees (inheritance).

⏱ ≈1.5 h practice unit · Code: copy, paste, practise · 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.

⚡ Key Points

  • Class = blueprint; object = the built thing; new = the building moment.
  • Properties are an object's facts (nouns); methods are its abilities (verbs).
  • The constructor runs at new time and hands the object what it needs — usually the browser page.
  • this.page means "the page stored on THIS object" — verbs act on the object's own nouns.
  • Inheritance is "is a" and couples child to parent; composition is "has a" — the framework's choice.

📖 Read

A class is a blueprint — a description of a thing. An object is an actual thing built from that blueprint: one blueprint, many houses; one recipe, many cakes. In the source module's real code, HomePage is the class, and the word new is the building moment: const po = new HomePage(page); — po is the object, the house you can actually walk into. Every Page Object you will ever read is built on these two words.

A class holds two kinds of things. Properties are the facts an object remembers — a page's expected title is the source example: readonly expectedTitle = "Aoma AI Agency — Get Found. Miss Fewer Leads."; Methods are the things it can do. The facts arrive through the constructor, a special method that runs the moment an object is built with new: constructor(page: Page) { this.page = page; } — it receives the browser page and stores it, and this.page means "the page stored on THIS object." Think of the constructor as the clock-in moment: the waiter is handed their section before taking any orders.

Methods are the class's verbs, and you call one on an object: po.goto() reads as an instruction — "po: go." A method acts on the object's own nouns: async goto() { await this.page.goto(this.path); } uses this.page and this.path, the facts the constructor stored. Classes can also share code two ways. Inheritance is "is a" — class PrivacyPage extends BasePage inherits everything BasePage has; powerful, but tightly coupled, because changing the parent changes every child. Composition is "has a" — a page HAS A Header component, shared by every page, changed in one place. This framework prefers composition: LEGO bricks you can swap, not a family tree whose traits cannot be handed back.

💻 Code for this unit — copy, paste, practise

The original worked code for this unit, verbatim, with its line-by-line explanations. Run it against the course practice project (download on the course page).

O-01 · Example 1 — OOP · classes & objects

class HomePage { /* the blueprint */ }

const po = new HomePage(page);

HomePage is the class. The word new builds one object from it. po is that object — the house you can actually walk into.

O-02 · Example 1 — OOP · properties & the constructor

readonly expectedTitle = "Aoma AI Agency — Get Found. Miss Fewer Leads.";

constructor(page: Page) {
  this.page = page;
}

expectedTitle is a fact HomePage carries. The CONSTRUCTOR is a special method that runs the moment an object is built with new — here it receives the browser page and stores it: this.page means “the page stored on THIS object.”

O-03 · Example 1 — OOP · methods

async goto() {
  await this.page.goto(this.path);
}

A method can use the object's own properties — this.page and this.path, the facts from O-02. Verbs act on the object's nouns. That's most of OOP, honestly.