Vibe Coding
AI Vibe CodingIntermediate84% · Assisted

Playwright E2E Self-Healing Tests: A Vibe Coding Acceptance Gate

Achieving 84% automation coverage by eliminating flaky failures through semantic locators and AI diagnostic skills

Est. time: 55 minUpdated: 2026-11-26
Cursor IDEPlaywrightGitHub ActionsMCP Browser
Playwright E2E Self-Healing Tests: A Vibe Coding Acceptance Gate

Completion Score

Overall completion is at 84%. AI excels at generating test cases and automatically fixing selectors, but diagnostic accuracy in complex async race condition scenarios still has room for improvement. Human intervention is primarily focused on reviewing the accuracy of business logic assertions and tuning CI resources.

84%Assisted

Dimension breakdown

Semantic Locators and Flakiness Prevention90%

Mandates the use of getByRole and data-testid, avoiding CSS selectors to ensure test stability when DOM structures change.

Core Business Flow Coverage88%

Covers critical paths such as login, order placement, and payment. AI automatically generates test cases to ensure no core functionality is missed.

Async Race Conditions and Flaky Failure Diagnosis80%

The AI diagnostic skill identifies most timing issues, but complex race conditions still require manual analysis of Trace logs.

CI Sharding, Concurrency, and Reporting78%

Basic sharding and retries are configured, but the lack of dynamic resource scheduling may impact execution speed under high load.

Human checkpoint

Humans must review AI-generated test assertions to ensure they accurately cover core business logic and verify that the CI sharding strategy matches current hardware resources to avoid resource contention caused by excessive concurrency.

Upgrade / downgrade path

If resources are constrained, downgrade to single-shard serial execution and disable video recording. For higher stability, introduce Playwright Test Runner's sharding feature and increase the retry count.

When to use & prerequisites

Ideal for mid-to-senior teams using Cursor IDE for frontend development. The environment requires Node.js 18+ and Playwright dependencies. The optimal scenario is high-velocity projects that need to quickly verify critical business flows after every commit and automatically pinpoint regression defects.

Ready-to-copy configs

playwright.config.tstypescript

定义 Playwright 测试环境、分片策略、重试机制及报告输出路径,确保 CI 稳定性与可追溯性。

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests/e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 4 : undefined,
  reporter: process.env.CI ? 'github' : 'html',
  use: {
    baseURL: process.env.APP_BASE_URL || 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
    actionTimeout: 10_000,
    navigationTimeout: 30_000,
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
  webServer: {
    command: 'npm run start',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
  },
});
.cursor/skills/playwright-triage/SKILL.mdmarkdown

指导 AI 助手在测试失败时自动分析 Trace、定位选择器失效原因并生成修复建议的标准化流程。

# Playwright Triage Skill

## Trigger
When `npx playwright test` fails, execute this triage protocol.

## Protocol
1. **Locate Trace**: Find the latest `.trace` file in `test-results/`.
2. **Analyze Snapshot**: Use MCP Browser to inspect the DOM at the failure point.
3. **Identify Root Cause**:
   - **Selector Mismatch**: Check if `data-testid` or semantic role is missing/changed.
   - **Timing Issue**: Check if `waitForSelector` or `expect` timeout was hit.
   - **State Pollution**: Check if previous test steps left global state.
4. **Generate Fix**:
   - Update locator to use `getByRole` or `getByTestId`.
   - Add explicit `waitFor` if async race condition is detected.
   - Isolate state if pollution is found.
5. **Verify**: Re-run the specific test file.

## Rules
- Never use `XPATH` or `CSS` selectors unless no semantic alternative exists.
- Always prefer `getByRole` for interactive elements.
- If flake is suspected, increase `actionTimeout` temporarily for diagnosis.

AI Vibe Coding in 4 steps

  1. 1

    Initialize Playwright Configuration

    Goal: Establish a stable testing foundation and configure sharding and reporting strategies.

    Prompt
    Initialize the Playwright testing environment and configure playwright.config.ts. Requirements: 1. Use the Chromium project; 2. Enable on-first-retry tracing and only-on-failure screenshots; 3. Enable 4 workers and 2 retries in CI environments; 4. Configure webServer to automatically start local services.

    Verify: Run `npx playwright test --list` to confirm that test files are correctly recognized and there are no configuration errors.

  2. 2

    Define Semantic Locator Standards

    Goal: Establish anti-flakiness selector standards to ensure test stability.

    Prompt
    Create .cursor/skills/playwright-triage/SKILL.md to define the Playwright test failure diagnostic workflow. Requirements: 1. Mandate the use of getByRole and getByTestId; 2. Prohibit the use of XPATH and CSS selectors; 3. Include Trace analysis steps and logic for generating fix recommendations.

    Verify: Inspect the SKILL.md file content to confirm it includes all mandatory rules and diagnostic steps.

  3. 3

    Generate Core Business Test Cases

    Goal: Cover critical paths like login and order creation to ensure no core functionality is missed.

    Prompt
    Generate E2E test cases for the /vibe-coding page, covering the following scenarios: 1. User login flow; 2. Creating a new project; 3. Saving configurations. Requirements: 1. Use getByRole to locate buttons and input fields; 2. Add expect assertions to verify UI state; 3. Use test.describe to organize the test structure.

    Verify: Run `npx playwright test tests/e2e/core-flows.spec.ts` to confirm all test cases pass.

  4. 4

    Integrate AI Diagnostic Skill

    Goal: Implement automatic diagnosis and fix recommendation generation after test failures.

    Prompt
    Integrate the Playwright Triage Skill into Cursor IDE. Requirements: 1. Automatically read .trace files when a test fails; 2. Use MCP Browser to analyze DOM snapshots; 3. Generate fix recommendations and update test code; 4. Re-run tests to verify the fix.

    Verify: Intentionally modify a selector to cause a test failure and observe whether the AI automatically diagnoses the issue and generates fix recommendations.

Pitfalls & fixes

  • Selectors that are too specific cause test failures when the DOM changes. Fix: Use getByRole and data-testid instead of CSS selectors.
  • Async race conditions cause flaky failures. Fix: Add explicit waitFor calls or increase actionTimeout.
  • CI resource contention causes slow execution. Fix: Optimize the sharding strategy and reduce the number of concurrent workers.

FAQ

Why do AI-generated test cases sometimes experience flaky failures?

This is usually due to async race conditions or overly specific selectors. It is recommended to check Trace logs to confirm timing issues and use semantic locators instead of CSS selectors.

How can CI execution speed be optimized?

You can enable sharded parallel execution by increasing the number of workers, but be mindful of resource contention. It is recommended to dynamically adjust the worker count based on CI machine configuration and disable unnecessary video recording.

Can the AI diagnostic skill automatically fix all test failures?

No. AI can diagnose most selector failures and timing issues, but complex business logic errors still require manual review. It is recommended to use AI diagnostics as an auxiliary tool and have humans confirm the fix before committing.

Related blueprints

Playwright E2E Self-Healing Tests: A Vibe Coding Acceptance Gate · CursorHome