Manuals / Test Automation / Chapter 8

C · Structure · intermediate · Week 4–5 · Chapter 8 of 12

Page objects, data, and waits

Structure is kindness to future-you. Hide selectors behind intent, seed data via API, and wait for conditions — never sleep.

Path progress
60%

Step 1 of 4

Extract a page object

Methods named like user intent: loginAs(user), addItem(name). Selectors live in one place.

Extract a page objectDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Extract a page objdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

// Conceptual POM
class LoginPage {
  constructor(page) { this.page = page; }
  async loginAs(user, pass) {
    await this.page.getByPlaceholder("Username").fill(user);
    await this.page.getByPlaceholder("Password").fill(pass);
    await this.page.getByRole("button", { name: "Login" }).click();
  }
}

Do this now

Refactor your login test into a LoginPage with loginAs(username, password) method.

Was this step clear?
Chapter learning outcomes
  • POM / screenplay ideas
  • Fixture data
  • Deterministic waits

Clear these before you leave

Side quest

Stabilize a flake

Reproduce a flake 5 times. Fix root cause. Document in FLAKES.md with cause and fix.