playwright-expert

Writes and debugs Playwright end-to-end tests using Page Object Model and role-based locators.

Updated Sep 1, 2021
One-click install
npx skills add https://github.com/WP-Coaching/pellegrims.coach --skill playwright-expert-wp-coaching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: playwright-expert
Source: https://github.com/WP-Coaching/pellegrims.coach/tree/main/.agents/skills/playwright-expert
Command: npx skills add https://github.com/WP-Coaching/pellegrims.coach --skill playwright-expert-wp-coaching

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing reliable browser tests is hard: brittle selectors, flaky timing issues, and poor test structure cause constant CI failures. This Skill provides expert guidance for building maintainable Playwright test suites that run consistently in CI/CD pipelines. ## Core Features & Use Cases - Test Architecture: Implements Page Object Model patterns, custom fixtures, and component page objects for maintainable test code. - Flaky Test Debugging: Diagnoses race conditions, animation timing, and network issues using trace viewer, auto-waiting locators, and proper wait strategies. - API Mocking & Configuration: Covers route interception, HAR file mocking, authentication setup, multi-browser projects, and CI integration. - Use Case: When your E2E tests fail intermittently in CI, use this Skill to identify the root cause (e.g., missing waitForResponse) and refactor tests with role-based selectors and proper isolation. ## Quick Start Ask the assistant to write a Playwright test for your login flow using the Page Object Model pattern with role-based selectors.

Frequently Asked Questions about playwright-expert

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Playwright tests with Page Object Model?

Create a class per page that exposes locators as readonly properties and methods for user actions, then instantiate it in tests with the page object. Use custom fixtures via test.extend() to share page objects and authenticated state across tests.

What are the best selectors to use in Playwright tests?

Use getByRole() for buttons, links, and inputs first, then getByLabel() for form fields and getByTestId() for non-semantic elements. Avoid CSS class selectors and XPath since they break easily when the UI changes.

Why are my Playwright tests flaky in CI?

Flakiness usually comes from race conditions, animations, network timing, or shared state between tests. Fix it by relying on auto-waiting locators, using waitForResponse for network calls, isolating test state, and never using waitForTimeout.

How do I mock API responses in Playwright tests?

Use page.route() with route.fulfill() to return mock JSON responses, route.continue() to pass requests through, or route.fetch() to modify real responses. You can also record and replay responses with routeFromHAR().

Does Playwright support testing on multiple browsers and devices?

Yes, playwright.config.ts supports projects for Chromium, Firefox, WebKit, and mobile device emulation like Pixel 5 or iPhone 13 using the devices descriptor. Tests run in parallel across all configured projects.

How do I debug a failing Playwright test?

Run with PWDEBUG=1 to open the inspector, use --headed to watch the browser, or enable trace: 'retain-on-failure' and inspect the trace with npx playwright show-trace. The --ui flag opens an interactive UI mode for step-by-step debugging.