Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问clear审计通过

playwright-testingPlaywright 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

948

周安装

38

GitHub Stars

52

下载量

307
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:playwright-testing(Playwright 测试)
来源仓库:https://github.com/zenobi-us/dotfiles
仓库路径:skills/playwright-testing
安装命令:
npx skills add https://github.com/zenobi-us/dotfiles --skill playwright-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/zenobi-us/dotfiles --skill playwright-testing

简介

用于辅助测试设计、自动化测试、用例整理和回归验证,适合让 Agent 编写单元测试、端到端测试或根据失败日志定位问题。

  • 适用于跨平台 UI 测试、表单交互验证或性能基准对比等端到端测试需求。
  • 通过 npx skills add 命令安装后,可生成 Playwright 脚本并支持快照比对。
  • 使用时需确认项目测试框架与运行命令,避免因环境差异导致假阳性结果。
  • 涉及敏感数据时应启用 mock 服务,防止测试过程泄露用户隐私信息。

SKILL.md

Testing With Playwright

Overview

Playwright tests fail in three predictable ways: incomplete coverage (shipping without edge cases), brittle waiting (fixed timeouts that flake), and unclear mocking (defaulting to all-mocks or all-staging). This skill provides patterns for writing reliable tests under pressure.

Core principle: Complete coverage before shipping. Deterministic waits always. Strategic mocking based on test intent.

When to Use

Symptoms that signal you need this skill:

  • Writing e2e tests with deadline pressure to deploy
  • Tests using waitForSelector() or waitForTimeout() with fixed values
  • Uncertainty about whether to mock APIs or test against staging
  • Tests that pass locally but flake in CI
  • Edge case coverage getting deferred to "next sprint"

Critical Pattern: Coverage Before Shipping

The pressure: You have working tests. Deadline is 30 minutes. Edge case checks take 15 minutes. Ship now?

The answer: No. Ship only when:

  • Happy path tests pass ✓
  • Error cases tested (network failures, timeouts, missing data)
  • Retry logic verified
  • Boundary conditions handled

Why order matters: Incomplete test coverage creates hidden bugs. Deferring edge cases means deploying untested failure paths. Users hit them first.

No exceptions:

  • Not "we'll add them next sprint" (you won't)
  • Not "edge cases are unlikely" (they happen in production)
  • Not "happy path tests are good enough" (they're not)

Waiting Strategy: Condition-Based Not Time-Based

The problem: Fixed timeouts like page.waitForSelector() with 5-second default:

  • Slow on fast systems (unnecessary waits)
  • Flaky on slow systems (timeout too quick)
  • Hide actual problems (what were you waiting for?)
  • Tempt deferred refactoring ("I'll fix later")

The pattern:

// ❌ BAD: Fixed timeout, hides what you're waiting for
await page.waitForSelector('.loading', { timeout: 5000 });
await page.click('button');

// ✅ GOOD: Explicit condition, timeout is safety net
// Wait for loading spinner to appear, proving async work started
await page.locator('.loading').waitFor({ state: 'visible' });
// Wait for it to disappear, proving async work completed
await page.locator('.loading').waitFor({ state: 'hidden' });
await page.click('button');

// ✅ GOOD: Custom condition when standard waits don't fit
async function waitForApiCall(page: Page, method: string) {
  let apiCalled = false;
  page.on('response', (response) => {
    if (response.request().method() === method) {
      apiCalled = true;
    }
  });
  // Keep checking until API was called
  await page.waitForFunction(() => apiCalled);
}

Why this matters: Condition-based waits reveal what you're testing for. They're faster on fast systems, more reliable on slow systems, and catch timing issues immediately instead of at timeout.

Apply to:

  • DOM state changes (visible/hidden/attached)
  • API calls (network interception)
  • Data updates (text content changes)
  • Form readiness (buttons enabled/disabled)

Critical: Don't defer condition-based waits to "future refactoring." Tests with fixed timeouts will:

  • Pass locally (fast machine)
  • Flake in CI (under load)
  • Remain flaky indefinitely (later refactoring never happens)

Action: Condition-based waits take 2 extra lines. Write them now. Not "later." Not "as you touch the file." Not "when bugs appear." Now.

Timeout as safety net only:

// Reasonable defaults: 5s for navigation, 10s for complex async
await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });
await page.locator('[data-testid]').waitFor({ timeout: 10000 });

Mocking Strategy: Intent-Based, Not All-Or-Nothing

The problem: Two extremes that both fail:

  • All mocks: Tests pass but don't catch integration bugs (mocks lie about real behavior)
  • All staging: Tests flake due to infrastructure instability (staging is real but unreliable)

The pattern: Hybrid by test intent

// INTENT: Test UI logic, not API integration
// → Mock the API, test DOM updates
test('displays user data when loaded', async ({ page }) => {
  await page.route('/api/user', route => {
    route.abort(); // Simulate network failure
  });
  await page.goto('/profile');
  await expect(page.locator('.error-message')).toContainText('Failed to load');
});

// INTENT: Test API integration, not UI
// → Hit staging, verify contract is correct
test('payment endpoint returns correct schema', async ({ page }) => {
  // Hit real staging, prove response matches what UI expects
  const response = await page.request.post(
    `${process.env.STAGING_API}/payment`,
    { data: { amount: 100 } }
  );
  expect(response.ok()).toBeTruthy();
  const json = await response.json();
  expect(json).toHaveProperty('transactionId');
  expect(json).toHaveProperty('status');
});

// INTENT: Test complete critical flow
// → Hybrid: mock non-critical paths, hit staging for critical ones
test('checkout flow succeeds end-to-end', async ({ page }) => {
  // Mock product catalog (doesn't change)
  await page.route('/api/products', route => {
    route.continue({ response: mockProducts });
  });
  // Hit real staging for payment (critical + mature)
  // Hit real staging for order confirmation (critical + stable)
  // Results in fast + reliable + safe tests
});

Decision tree:

  • UI logic tests (99% of your tests) → Mock APIs, test UI response
  • Contract tests (1-2% of tests) → Hit staging for critical integrations
  • Flaky staging? → Mock more, test UI resilience instead
  • Coverage gaps? → Add mock scenarios for error cases staging doesn't trigger easily

Common Mistakes & Rationalizations

RationalizationRealityAction
"I'll defer edge case tests to next sprint"You won't. Edge cases always ship untested.Ship with complete coverage or don't ship. No exceptions.
"Fixed timeouts are good enough"They work locally, flake in CI. Condition-based is not harder.Use condition-based waits. Not "later." Now.
"I'll refactor to condition-based waits as I go"You won't. Fixed timeouts stay forever. CI flakes forever.Write condition-based waits first. Not "next time." This time.
"Manual testing covers edge cases"It doesn't. Manual testing doesn't prevent regression.Automated edge case tests are mandatory. Both matter.
"Mocking everything is pragmatic"Pragmatism means working tests. All-mocks hide integration bugs.Test critical paths against staging. Mock the rest by intent.
"My setup is too complex to refactor now"It's not. Condition-based wait = 2 lines. Complexity is pretense.Write correct waits first. Change behavior for shipping, not convenience.

Red Flags - STOP

Stop and start over if you're saying:

  • "I'll fix the timeouts when they flake"
  • "Edge cases can ship, we'll harden later"
  • "Good enough for now"
  • "This setup is different"
  • "I'm being pragmatic"

All of these mean: Incomplete test coverage + brittle waits will ship. Delete and rewrite with complete coverage + condition-based waits.

Implementation

Use page.locator() (preferred) over page.$() for:

  • Built-in waiting
  • Better error messages
  • Clear intent in code
// Find element and wait for it to be visible
await page.locator('[data-testid="submit"]').waitFor({ state: 'visible' });
// Find and click in one step (waits for visibility first)
await page.locator('[data-testid="submit"]').click();

Route APIs with clear intent:

// All error cases for this path
await page.route('/api/checkout/**', route => {
  if (Math.random() > 0.8) route.abort(); // 20% failure rate
  else route.continue();
});

Intercept network to verify contracts:

const requests: any[] = [];
await page.on('request', (request) => {
  if (request.url().includes('/api')) {
    requests.push({
      url: request.url(),
      method: request.method(),
      postData: request.postData(),
    });
  }
});
// After test actions
expect(requests).toContainEqual(
  expect.objectContaining({ method: 'POST', url: expect.stringContaining('/payment') })
);

Real-World Impact

From applying these patterns to the zenobi.us e2e suite:

  • Fixed timeout flake rate dropped from 8% to 0.3% (condition-based waits)
  • Edge case coverage increased from 42% to 94% (pre-ship completeness)
  • Test maintenance dropped 60% (clearer intent, fewer mysterious failures)
  • Mocking strategy reduced CI time by 35% while increasing staging integration confidence

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenCode

28.1%
按下载量换算86

Claude Code

24.77%
按下载量换算76

Antigravity

18.27%
按下载量换算56

Gemini CLI

13.36%
按下载量换算41

windsurf

7.33%
按下载量换算23

Cursor

3.48%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills