Agent SkillsTangleML/tangle-ui › e2e-testing

e2e-testing

GitHub

提供基于 Playwright 的端到端测试最佳实践,涵盖选择器使用、自动等待、断言模式及测试隔离等规范,指导 E2E 测试的编写、修改与审查。

.claude/skills/e2e-testing/SKILL.md TangleML/tangle-ui

Trigger Scenarios

编写或修改 E2E 测试代码 审查 E2E 测试用例

Install

npx skills add TangleML/tangle-ui --skill e2e-testing -g -y
More Options

Non-standard path

npx skills add https://github.com/TangleML/tangle-ui/tree/master/.claude/skills/e2e-testing -g -y

Use without installing

npx skills use TangleML/tangle-ui@e2e-testing

指定 Agent (Claude Code)

npx skills add TangleML/tangle-ui --skill e2e-testing -a claude-code -g -y

安装 repo 全部 skill

npx skills add TangleML/tangle-ui --all -g -y

预览 repo 内 skill

npx skills add TangleML/tangle-ui --list

SKILL.md

Frontmatter
{
    "name": "e2e-testing",
    "description": "Playwright E2E testing best practices for this project. Use when writing, modifying, or reviewing E2E tests."
}

E2E Testing Best Practices (Playwright)

Setup

  • Use Playwright helpers from tests/e2e/helpers.ts
  • Use data-testid attributes for stable selectors
  • Write descriptive test names that explain user behavior
  • Ensure tests are isolated and can run independently

Never Use Hard-Coded Timeouts

// Bad
await element.click();
await page.waitForTimeout(200);

// Good
await element.click();
await expect(otherElement).toBeVisible();

Use Playwright's Auto-Waiting

// Bad
if (await element.isVisible()) {
  await element.click();
}

// Good
await expect(element).toBeVisible();
await element.click();

Never Use Non-Null Assertions

// Bad
const box = await element.boundingBox();
const x = box!.x;

// Good
const box = await element.boundingBox();
if (!box) {
  throw new Error("Unable to locate element bounding box");
}
const x = box.x;

Don't Await Locators (They're Lazy)

// Bad
const button = await page.getByTestId("submit");

// Good
const button = page.getByTestId("submit");
await expect(button).toBeVisible();

Use Consistent Assertion Patterns

// Bad
expect(await element).toHaveText("text");
expect(await element.isVisible()).toBe(true);

// Good
await expect(element).toHaveText("text");
await expect(element).toBeVisible();

Prefer Semantic Selectors

Priority order:

  1. getByRole() - Best for accessibility
  2. getByTestId() - Best for test stability (preferred for this app)
  3. getByText() - Good for static content
  4. locator() with data attributes - When above don't work
  5. CSS selectors - Last resort

Test Isolation

  • Each test should set up its own state
  • Don't depend on test execution order (unless using serial mode intentionally)
  • Clean up after tests in afterEach or afterAll

Helper Functions

  • Leverage existing helpers from tests/e2e/helpers.ts
  • Create new helpers for repeated workflows
  • Keep helpers focused and reusable

Add Meaningful Error Context

// Okay
await expect(element).toBeVisible();

// Better
await expect(element, "Component should appear after loading").toBeVisible();

Test User Behavior, Not Implementation

// Bad - implementation detail
await expect(button).toHaveClass("bg-blue-500");

// Good - user-visible behavior
await expect(button).toBeVisible();
await expect(button).toBeEnabled();
await expect(button).toHaveText("Submit");

Version History

  • d7768e8 Current 2026-09-02 20:59

Same Skill Collection

.claude/skills/accessibility/SKILL.md
.claude/skills/address-pr-comments/SKILL.md
.claude/skills/analytics-tracking/SKILL.md
.claude/skills/audit-tickets/SKILL.md
.claude/skills/docs-update/SKILL.md
.claude/skills/list-skills/SKILL.md
.claude/skills/open-source/SKILL.md
.claude/skills/project-conventions/SKILL.md
.claude/skills/react-patterns/SKILL.md
.claude/skills/review/SKILL.md
.claude/skills/tangle-domain/SKILL.md
.claude/skills/tanstack-query/SKILL.md
.claude/skills/tanstack-router/SKILL.md
.claude/skills/typescript-standards/SKILL.md
.claude/skills/ui-primitives/SKILL.md
.claude/skills/validate/SKILL.md
.claude/skills/vitest-testing/SKILL.md
.cursor/skills/playwright-testing/SKILL.md
public/agent-skills/componentYamlFormat/SKILL.md
public/agent-skills/tangleBestPractices/SKILL.md
.claude/skills/gardening/SKILL.md

Metadata

Files
0
Version
d7768e8
Hash
a3c071c5
Indexed
2026-09-02 20:59

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-03 03:18
浙ICP备14020137号-1 $bản đồ khách truy cập$