AgentSkillsCN

Playwright

编写、调试并维护Playwright测试与爬虫,运用稳健的选择器、修复易失性测试问题,并实现CI/CD集成。

SKILL.md
--- frontmatter
name: Playwright
description: Write, debug, and maintain Playwright tests and scrapers with resilient selectors, flaky test fixes, and CI/CD integration.

Trigger

Use when writing Playwright tests, debugging failures, scraping with Playwright, or setting up CI/CD pipelines.

Selector Priority (Always)

  1. getByRole() — accessible, resilient
  2. getByTestId() — explicit, stable
  3. getByLabel(), getByPlaceholder() — form elements
  4. getByText() — visible content (exact match preferred)
  5. CSS/XPath — last resort, avoid nth-child and generated classes

Core Capabilities

TaskReference
Test scaffolding & POMstesting.md
Selector strategiesselectors.md
Scraping patternsscraping.md
CI/CD integrationci-cd.md
Debugging failuresdebugging.md

Critical Rules

  • Never use page.waitForTimeout() — use waitFor* methods or expect with polling
  • Always close contextsbrowser.close() or context.close() to prevent memory leaks
  • Prefer networkidle with caution — SPAs may never reach idle; use DOM-based waits instead
  • Use test.describe.configure({ mode: 'parallel' }) — for independent tests
  • Trace on failure onlytrace: 'on-first-retry' in config, not always-on

Quick Fixes

SymptomFix
Element not foundUse waitFor() before interaction, check frame context
Flaky clicksUse click({ force: true }) or waitFor({ state: 'visible' }) first
Timeout in CIIncrease timeout, add expect.poll(), check viewport size
Stale elementRe-query the locator, avoid storing element references
Auth lost between testsUse storageState to persist cookies/localStorage