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 progress60%
Step 1 of 4
Extract a page object
Methods named like user intent: loginAs(user), addItem(name). Selectors live in one place.
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.