playwright-page-object-model
БесплатноБез исполняемых скриптовНе проверенUse when creating page objects or refactoring Playwright tests for better maintainability with Page Object Model patterns.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Playwright Page Object Model
Master the Page Object Model (POM) pattern to create maintainable, reusable, and scalable test automation code. This skill covers modern Playwright patterns including component-based architecture, locator strategies, and app actions.
Core POM Principles
Single Responsibility
Each page object should represent one page or component with a single, well-defined responsibility.
Encapsulation
Hide implementation details and expose only meaningful actions and assertions.
Reusability
Create reusable components that can be composed into larger page objects.
Maintainability
When UI changes, update page objects in one place rather than across multiple tests.
Basic Page Object Pattern
Simple Page Object
// pages/login-page.ts
import { Page, Locator } from '@playwright/test';
export class LoginPage {
readonly page: Page;
readonly emailInput: Locator;
readonly passwordInput: Locator;
readonly loginButton: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
this.emailInput = page.getByLabel('Email');
this.passwordInput = page.getByLabel('Password');
this.loginButton = page.getByRole('button', { name: 'Login' });
this.errorMessage = page.getByRole('alert');
}
async goto() {
await this.page.goto('/login');
}
async login(email: string, password: string) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.loginButton.click();
}
async getErrorMessage() {
return await this.errorMessage.textContent();
}
}
Using Page Object in Tests
// tests/login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/login-page';
test.describe('Login', () => {
test('should login successfully', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('[email protected]', 'password123');
await expect(page).toHaveURL('/dashboard');
});
test('should show error on invalid credentials', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('[email protected]', 'wrongpassword');
const error = await loginPage.getErrorMessage();
expect(error).toContain('Invalid credentials');
});
});
Locator Strategies
Recommended Locator Priority
- User-visible locators (getByRole, getByText, getByLabel)
- Test IDs (getByTestId)
- CSS/XPath (only as last resort)
User-Visible Locators
export class HomePage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
// By role (ARIA role)
get searchButton() {
return this.page.getByRole('button', { name: 'Search' });
}
// By label (form inputs)
get searchInput() {
return this.page.getByLabel('Search products');
}
// By text
get welcomeMessage() {
return this.page.getByText('Welcome back');
}
// By placeholder
get emailInput() {
return this.page.getByPlaceholder('Enter your email');
}
// By alt text (images)
get logo() {
return this.page.getByAltText('Company Logo');
}
// By title
get helpIcon() {
return this.page.getByTitle('Help');
}
}
Test ID Locators
// Component with test IDs
// <button data-testid="submit-button">Submit</button>
export class FormPage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
get submitButton() {
return this.page.getByTestId('submit-button');
}
get formContainer() {
return this.page.getByTestId('form-container');
}
}
Locator Chaining
export class ProductPage {
readonly page: Page;
constructor(page: Page) {
this.page = page;
}
// Chain locators for specificity
get priceInCart() {
return this.page
.getByTestId('shopping-cart')
.getByRole('cell', { name: 'Price' });
}
// Filter locators
getProductByName(name: string) {
return this.page
.getByRole('listitem')
.filter({ hasText: name });
}
// Nth element
get firstProduct() {
return this.page.getByRole('article').nth(0);
}
}
Component-Based Architecture
Reusable Component Objects
// components/navigation.ts
export class Navigation {
readonly page: Page;
readonly homeLink: Locator;
readonly productsLink: Locator;
readonly cartLink: Locator;
readonly profileMenu: Locator;
constructor(page: Page) {
this.page = page;
this.homeLink = page.getByRole('link', { name: 'Home' });
this.productsLink = page.getByRole('link', { name: 'Products' });
this.cartLink = page.getByRole('link', { name: 'Cart' });
this.profileMenu = page.getByRole('button', { name: 'Profile' });
}
async navigateToHome() {
await this.homeLink.click();
}
async navigateToProducts() {
await this.productsLi
Установить playwright-page-object-model в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadWriteEditFAQ
Что делает скилл playwright-page-object-model?
Use when creating page objects or refactoring Playwright tests for better maintainability with Page Object Model patterns.
Как установить скилл playwright-page-object-model?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл playwright-page-object-model запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic