Page Object Model
Keep page details in one place so tests stay easy to read.
What you'll learn
- Put locators and actions in one class.
- Make tests shorter and easier to update.
- Hide selector noise behind clear names.
Playwright AutomationlessonsJump to another lesson
Page Object Model
Keep page details in one place so tests stay easy to read.
Big Picture
One small picture can make this idea easier to hold.
Raw selectors
- Selectors repeat in many tests.
- Tests are long.
- Small UI change breaks many lines.
- Hard to read.
Page objects
- Selectors live in one class.
- Tests read like stories.
- UI change has one fix.
- Easy to reuse actions.
VerdictPage objects win when many tests touch the same page.
How It Moves
Short steps make the flow easier to see.
Find parts
List the buttons, fields, and links on the page.
Wrap them
Put locators inside one page class.
Add actions
Create methods like login or search.
Use in tests
Call clear methods instead of raw selectors.
Step By Step
This is the same idea, stretched across time.
- 1
Start with selectors
You first find the page elements you need.
- 2
Build the page class
You move locators and actions into one object.
- 3
Write simple tests
Tests call methods like a user flow.
- 4
Change only one place
A UI update should touch one page object.
One Small Model
Think of this like a tiny card you can keep in your pocket.
LoginPage
5 fieldsQuick Check
What is the main job of a page object?
Map It
One more picture helps you see where this lesson matters most.
Where page objects help most
Small and simple
One test for one page
Best fit
Many tests reuse login
Still useful
Few screens but shared steps
Very useful
Large app with shared flows