← 返回
未分类

1xjy

E2E testing specialist with Playwright. Creates test journeys, manages flaky tests, handles artifacts. Uses POM pattern and semantic locators. Waits for conditions, not time.
user_23af92d1
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 94
下载
💾 0
安装
1
版本
#latest

概述

E2E Runner Skill

End-to-end testing specialist using Playwright. Creates reliable, maintainable test journeys.

Test Journey Creation

  1. Define user flow: Login → action → assertion
  2. Use semantic locators: role, label, placeholder over CSS/XPath
  3. One journey per file: Logical grouping (e.g., auth.spec.ts, checkout.spec.ts)
  4. Arrange-Act-Assert: Clear structure in each test

Page Object Model (POM)

// pages/LoginPage.ts
export class LoginPage {
  constructor(private page: Page) {}

  async goto() {
    await this.page.goto('/login');
  }

  async login(email: string, password: string) {
    await this.page.getByRole('textbox', { name: /email/i }).fill(email);
    await this.page.getByRole('textbox', { name: /password/i }).fill(password);
    await this.page.getByRole('button', { name: /sign in/i }).click();
  }

  async expectLoggedIn() {
    await expect(this.page.getByRole('link', { name: /dashboard/i })).toBeVisible();
  }
}

Semantic Locators (Preferred Order)

  1. getByRole('button', { name: 'Submit' }) — accessibility-friendly
  2. getByLabel('Email') — form fields
  3. getByPlaceholder('Enter email') — when no label
  4. getByText('Welcome') — unique text
  5. getByTestId('submit-btn') — last resort; requires data-testid

Avoid: getByCss, getByXPath for dynamic selectors; brittle and slow.

Wait for Conditions, Not Time

// BAD - flaky
await page.waitForTimeout(2000);

// GOOD - wait for condition
await expect(page.getByRole('heading', { name: 'Success' })).toBeVisible();
await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.getByText('Saved')).toBeVisible({ timeout: 5000 });
  • Use expect(...).toBeVisible(), toBeEnabled(), etc.
  • Playwright auto-waits; explicit waits rarely needed
  • For network: page.waitForResponse() or page.waitForRequest()

Flaky Test Management

CauseMitigation
-------------------
TimingReplace waitForTimeout with condition waits
Race conditionsUse Promise.all for parallel; sequential for dependent
Shared stateIsolate: fresh page, clean DB, or unique test data
AnimationsWait for final state; disable animations in test config
External depsMock APIs; use test fixtures
Order dependencyTests should be independent; no shared order

Artifact Management

// playwright.config.ts
export default defineConfig({
  use: {
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
});
  • Trace: Inspect with npx playwright show-trace trace.zip
  • Screenshots: On failure for debugging
  • Video: Retain only on failure to save space

Running Tests

# Headed (see browser)
npx playwright test --headed

# Specific file
npx playwright test auth.spec.ts

# Debug mode
npx playwright test --debug

# UI mode (interactive)
npx playwright test --ui

Best Practices

  • Keep tests independent; no shared mutable state
  • Use data-testid sparingly; prefer semantic queries
  • One assertion focus per test when possible
  • Use fixtures for setup (auth, test data)
  • Run in CI with --retries=2 for transient failures

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-04-15 14:58 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 670 📥 324,316
ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 714 📥 243,984
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,217 📥 266,660