Manuals / Playwright with Python / Chapter 21

Part 3 · Test Structure & Framework · intermediate · ~55 min · Chapter 21 of 61

14. Page Object Model (POM)

Why POM, folder structure Without POM, locators get written directly inside test functions — meaning if the UI changes (a button's text, an ID), you have to hunt down and fix every test that touches that element. POM solves this by centralizing each page's locators and actions into a dedicated class, so a UI change means fixing one class, not dozens of tests.

Path progress
33%

Step 1 of 3

Overview

Why POM, folder structure Without POM, locators get written directly inside test functions — meaning if the UI changes (a button's text, an ID), you have to hunt down and fix every test that touches that element. POM solves this by centralizing each page's locators and actions into a dedicated class, so a UI change means fixing one class, not dozens of tests. project/ ├── pages/ │ ├── base_page.py │ ├── login_page.py │ └── dashboard_page.py ├── tests/ │ ├── test_login.py │ └── test_dashboard.py └── conftest.py Base Page class A BasePage holds behavior common to every page — navigation, generic waits — so individual page classes don't repeat it. python

OverviewDrag 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 →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →
Was this step clear?
Chapter learning outcomes
  • Why POM, folder structure Without POM, locators get written directly inside test
  • POM solves this by centralizing each page's locators and actions into a dedicate
  • project/ ├── pages/ │ ├── base_page.py

Clear these before you leave

Side quest

14. Page Object Model (POM) deliverable

Apply one idea from “Overview” in a small script or note.