playwright-page-objects
Skill122 starsChanged 37 days agoMITView on GitHub
Use when creating page objects or refactoring Playwright E2E tests for better maintainability with Page Object Model patterns.
In this repository18 other files it gives its agents.
- .agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/instructions/copilot-instructions.mdCopilot instructions
- agent-md-refactorSkill
- brainstormingSkill
- building-blocksSkill
- commit-workSkill
- dependency-updaterSkill
- explaining-codeSkill
- frontend-designSkill
- github-actions-templatesSkill
- qa-test-plannerSkill
- react-useeffectSkill
- test-building-blocksSkill
- test-driven-developmentSkill
- typescript-advanced-typesSkill
- vercel-react-best-practicesSkill
- writing-specSkill
The file
Files
Playwright Page Objects
Modern POM architecture using Playwright's fixtures pattern, composition over inheritance, and role-based locators.
When to Apply
- Setting up E2E test architecture from scratch
- Creating new page objects or component helpers
- Implementing test fixtures for dependency injection
- Refactoring existing page objects for maintainability
- Writing reusable component-level test abstractions
Core Principles
- Fixtures over PageManager — On-demand instantiation, automatic setup/teardown, native TypeScript inference
- Composition over inheritance — Compose from focused components, avoid deep class hierarchies
- Role-based selectors first —
getByRole()>getByLabel()>getByText()>getByTestId() - Tests own assertions — Page objects expose state via getters, tests make assertions
- Separate pages by workflow — ProductListPage ≠ ProductDetailsPage (different user interactions)
- Readonly locators — All page object locator properties should be
readonly - Fluent interfaces — Methods return
thisfor chaining; navigation methods return target page object - Private internals — Mark implementation details (spinners, retry logic, helpers) as
private - Wait for stability — Use
waitForPageLoad(),waitForResponse()before assertions - High-level actions — Create AppActions class for complex multi-page user flows
Quick Reference
| Pattern | When to Use | Reference |
| Fixtures | Always for page object instantiation | fixtures-pattern.md |
| Basic POM | All page objects | core-patterns.md |
| Composition | Shared UI elements (header, cards, modals) | core-patterns.md |
| Waiting strategies | Loading states, API responses | core-patterns.md |
| High-level actions | Multi-page flows (checkout, onboarding) | core-patterns.md |
| Form handling | Multi-step forms, validation | form-handling.md |
Locator Priority
1. page.getByRole('button', { name: 'Add to Cart' }) // Preferred
2. page.getByLabel('Email') // Form inputs
3. page.getByText('Welcome back') // Non-interactive
4. page.getByPlaceholder('Search...') // When no label
5. page.getByTestId('cart-item-count') // Escape hatchAnti-Patterns Summary
| Anti-Pattern | Problem | Solution |
| Assertions in POMs | Hidden test logic | Expose state, assert in tests |
| Fat page objects | 50+ locators unmaintainable | Split into components |
| Deep inheritance | Rigid, hard to modify | Use composition |
| CSS selectors | Break on styling changes | Use role-based selectors |
| Wrapping Playwright | Unnecessary abstraction | Use Playwright directly |
| All members public | Exposes internals | Mark internal members private |
References
- Fixtures Pattern — Setup and dependency injection
- Core Patterns — Basic POM, composition, locators, waiting, high-level actions
- Form Handling — Multi-step flows, validation components
- Anti-Patterns — What to avoid
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

