TOPIC 15/6022 MINNOT STARTED

Page objects in Playwright

Wrap one page in a TypeScript class with locators and action methods, so a Playwright test says addTask and not a string of clicks.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a remote control with named buttons. The television has many parts inside. The remote hides them behind Power and Volume. When the set is rebuilt, you still press Volume.

Daily List is a to-do list app. Tom's tests all repeat the same clicks to add a task. When Leo renames the Add button, twelve tests break at once.

What it is: Playwright is a library that drives a real browser. This slice is a : one class that stands for one page. A remembers how to find an element. An action method does one job a person does, such as addTask. The nearest neighbour is a test that spells out every click. Selenium's page objects are the older form of the same idea.

Why it matters: When Add task moves, Tom updates one class instead of twelve tests. The test reads as a story. It says add a task and check the row, and the markup stays inside the class.

A remote only has the buttons you put on it. The test still has to check the result. The class does not know whether the task really appeared.

(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)

PLAIN WORDS · 4 in this section
renames
gives a new name
playwright
a free Microsoft tool that drives a browser for tests
locator
a pointer telling you where to find something
selenium
A free tool that drives a web browser for checks.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Putting the finding and doing of one page in one class, so tests state goals and not clicks.

  1. Wrap the page
  2. Save the locators
  3. Name the goals
  4. Check in the test
Name the goal, hide the clicks

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A remote controlA page object
A named buttonAn action method such as addTask
The wiring inside the remoteThe locators inside the class
A new remote for a new televisionOne fix when the page changes

WHERE THIS PICTURE STOPS

  • A remote has a fixed set of buttons, but a page object has only the methods you write.
  • A remote does not judge the television, and a page object does not judge the result.
  • A remote with fifty buttons is hard to use, and so is a giant page object.

HOOK

Press the named button, not the wires.

REMEMBER IT THIS WAY

A rule of thumb: if you see this, think that.

If many tests repeat the same clicks, put them behind one method with a plain name, so a rename breaks one place.

What each part of the trick stands for
In the trickWhat it stands for
Same clickstests all repeat the same clicks to add a task
One methodAn action method does one job a person does

A page that only one test uses may not need its own class.

TELL A FRIEND

A remote control with named buttons. The test presses Volume and does not touch the wiring.

OFTEN MIXED UP WITH Fixtures: shared setup without copy-paste. A fixture builds and hands over set-up. A holds the locators and actions of a page.

Sources & standards — 3 sources
  1. Market practice

    Page object models (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Shows a page object as a class that wraps a Page, builds locators in the constructor and offers methods for actions, and says locators are resolved just before each action. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Recommends user-facing locators such as role-based ones, web-first assertions that retry, and avoiding fixed waits (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  3. Market practice

    Fixtures (Playwright documentation) ↗ — Microsoft (Playwright) · A page object can be handed to tests through a fixture built with test.extend (search excerpt, page not opened)

    Says fixtures are set up per test, built with test.extend, hand a value to the test with use, are created only when a test asks for them, can be automatic with auto true and can be worker scoped with scope worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

PRACTISE AND KEEP

Sources for this topic — 3 sources
  1. Market practice

    Page object models (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.

    Shows a page object as a class that wraps a Page, builds locators in the constructor and offers methods for actions, and says locators are resolved just before each action. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-11-06

    Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.

  2. Market practice

    Best practices (Playwright documentation) ↗ — Microsoft (Playwright) · Recommends user-facing locators such as role-based ones, web-first assertions that retry, and avoiding fixed waits (search excerpt, page not opened)

    Recommends user-facing locators such as role-based ones over Cascading Style Sheets (CSS) or XPath, web-first assertions that retry, and avoiding fixed waits. Vendor documentation. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail. A second search on 2026-10-20 returned this page for its title and matched the described content; the page was still not opened (search excerpt, page not opened).

  3. Market practice

    Fixtures (Playwright documentation) ↗ — Microsoft (Playwright) · A page object can be handed to tests through a fixture built with test.extend (search excerpt, page not opened)

    Says fixtures are set up per test, built with test.extend, hand a value to the test with use, are created only when a test asks for them, can be automatic with auto true and can be worker scoped with scope worker. Vendor documentation for one tool. Practitioner guidance, not a standard. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.