Playwright POM Scaffolder
Purpose
To automate the creation of a professional-grade Playwright automation framework. This skill transforms a simple domain name and a set of automation goals into a fully structured project following industry best practices: Page Object Model (POM), strict TypeScript configuration, custom reporters, and modular design.
When to Use
Use this skill when:
- You need to start a new web automation project from scratch.
- You want to ensure the project follows the Page Object Model (POM) pattern.
- You need a custom reporter setup (e.g., HTML + JSON + Console).
- You want to standardize testing infrastructure across teams.
Core Capabilities
- Framework Scaffolding: Automatically creates directories for
pages,tests,utils, andreporters. - POM Implementation: Generates BasePage classes and specific Page Objects based on the target site.
- Configuration Generation: Creates a robust
playwright.config.tswith multi-browser support, tracing, and custom reporting. - Environment Setup: Initializes
package.jsonand installs necessary dependencies (@playwright/test,typescript, etc.). - Instructional Integration: Converts natural language automation requirements into actual test cases.
Workflow
Phase 1: Requirement Gathering
The assistant must first ask the user for:
- Target Domain/URL: e.g.,
https://example.com - Automation Goals: e.g., "Login flow, checkout process, and contact form validation."
- Preferred Language: TypeScript (recommended) or JavaScript.
Phase 2: Project Initialization
Execute these steps to set up the foundation:
# 1. Create project directory
mkdir playwright-automation
cd playwright-automation
# 2. Initialize npm
npm init -y
# 3. Install Playwright
npm install -D @playwright/test typescript @types/node
npx playwright install chromium
Phase 3: Directory Structure
Create a clean, modular structure:
mkdir -p pages tests utils reporters
Phase 4: Scaffolding Configuration
The assistant generates a playwright.config.ts that includes:
- Parallel execution settings.
- Retries and timeouts.
- Base URL configuration.
- Custom reporter integration.
Phase 5: POM Generation
- BasePage: A shared class for common actions (click, type, wait).
- Page Objects: Specific classes for each main page/section of the site (e.g.,
LoginPage,DashboardPage).
Phase 6: Test Generation
Generates .spec.ts files that:
- Import Page Objects.
- Follow the Arrange-Act-Assert pattern.
- Use descriptive
test.step()blocks for clean reporting.
Best Practices Followed
- Strict Locators: Prefers
getByRole,getByText, andgetByTestId. - Automatic Waiting: Leverages Playwright's built-in auto-waiting rather than hard sleeps.
- Independence: Each test is isolated and can run in parallel.
- Reporting: Configures custom reporters for better CI/CD visibility.
- Clean Code: Uses DRY (Don't Repeat Yourself) via the
utilsfolder and shared components.
Example Generated Structure
playwright-automation/
├── playwright.config.ts
├── package.json
├── tsconfig.json
├── pages/
│ ├── BasePage.ts
│ ├── LoginPage.ts
│ └── DashboardPage.ts
├── tests/
│ └── auth.spec.ts
├── utils/
│ └── test-data.ts
└── reporters/
└── custom-reporter.ts
Quality Standards
The generated framework must:
- Pass
npx tscif using TypeScript. - Be immediately runnable with
npx playwright test. - Contain a
README.mdwith clear execution and maintenance instructions. - Use environment variables for sensitive data like credentials.
References
- Playwright Official POM Guide: https://playwright.dev/docs/pom
- Best Practices: https://playwright.dev/docs/best-practices
- Custom Reporters: https://playwright.dev/docs/test-reporters#custom-reporters
Converted and distributed by TomeVault — claim your Tome and manage your conversions.