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.
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
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.