Reliable Playwright E2E Tests and Flake Fixes

Write reliable Playwright tests, diagnose CI flakiness, and configure isolated fixtures, mocks, visual checks, and CI.

Development / Testingplaywrighte2e-testing
by AgentVoltv1.0.0
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

Prompt“Write E2E tests for my app's login and checkout flows”
Beforegeneric AI agent
Playwright is a powerful tool for end-to-end testing of web applications. You'll want to write tests that simulate real user actions like clicking buttons and filling out forms accurately. Page Object Model is a useful pattern that helps organize and maintain your tests. You should test both happy paths and error scenarios to be thorough. Waiting for elements to appear is important for reliability - avoid hard waits if possible. You can run tests in parallel for speed and efficiency. CI integration is helpful for automating test runs. Would you like me to help set up the test structure, or do you need specific examples? I can guide you through the setup.
Afterwith Reliable Playwright E2E Tests and Flake Fixes
// loginPage.ts - Page Object Pattern
import { Page } from '@playwright/test';

export class LoginPage {
  constructor(private page: Page) {}

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

  async login(email: string, password: string) {
    await this.page.getByLabel('Email').fill(email);
    await this.page.getByLabel('Password').fill(password);
    await this.page.getByRole('button', {name: 'Sign in'}).click();
    await this.page.waitForURL('/dashboard');
  }

  async getErrorMessage() {
    return await this.page.getByRole('alert').textContent();
  }
}

// checkout.spec.ts - Test Suite
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/loginPage';
import { CheckoutPage } from './pages/checkoutPage';

test.describe('Checkout Flow', () => {
  test('Happy path: complete purchase', async ({page}) => {
    const loginPage = new LoginPage(page);
    const checkoutPage = new CheckoutPage(page);

    await loginPage.navigateTo();
    await loginPage.login('user@example.com', 'password123');
    
    await checkoutPage.navigateTo();
    await checkoutPage.addItemToCart('Pro Plan');
    await checkoutPage.fillShippingInfo('123 Main St');
    await checkoutPage.fillPayment('4242424242424242', '12/25', '123');
    await checkoutPage.submitOrder();
    
    await expect(page).toHaveURL('/order-confirmed');
    await expect(page.getByText('Order Confirmed')).toBeVisible();
  });

  test('Invalid login: wrong password', async ({page}) => {
    const loginPage = new LoginPage(page);
    await loginPage.navigateTo();
    await loginPage.login('user@example.com', 'wrongpassword');
    
    const error = await loginPage.getErrorMessage();
    expect(error).toContain('Invalid credentials');
  });
});

CONFIG: playwright.config.ts
  webServer: http://localhost:3000
  workers: 4 (parallel execution)
  timeout: 30000
  retries: 2 (flaky-test resilience)

KEY PRACTICES: Page Objects encapsulate selectors. getByRole and getByLabel are accessibility-first. Explicit waits via waitForURL/waitForSelector. No hard sleeps. CI runs headless via GitHub Actions. Screenshot artifacts on failure.

About this skill

Your Playwright tests pass locally, fail in CI, and pass again when retried. This skill turns those failures into specific fixes by tracing readiness, network timing, shared data, and browser state, then writing tests that verify the actual user outcome.

What it does

  • Replaces sleeps and premature assertions with explicit application readiness and observable completion conditions.
  • Builds strict, scoped locators that survive styling changes and expose ambiguous UI structure.
  • Designs isolated fixtures, authentication state, and test data that remain safe under parallel execution and retries.
  • Sets up targeted API mocks without accidentally removing the integration the test is supposed to cover.
  • Configures Playwright projects, failure artifacts, visual comparisons, and CI execution around the repository's installed version.
  • Reviews existing tests and returns concrete patches with a focused reproduction and verification plan.

What you get

Repository-ready tests or a focused fix, plus the assumptions and commands needed to verify it. For flaky failures, you get an evidence-based diagnosis that distinguishes a demonstrated cause from an untested hypothesis.

Best for

Developers and QA engineers maintaining Playwright Test suites, adding E2E coverage, or investigating browser tests that fail intermittently in CI.

SKILL.md preview

SKILL.md
---
name: reliable-playwright-e2e-tests-and-flake-fixes
description: >-
  Write and repair Playwright Test suites by identifying observable completion conditions, isolating browser and backend state, and diagnosing failures from traces and network evidence. Use when the user says "write a Playwright test", "my tests pass locally but fail in CI", "this browser test keeps flaking", "set up Playwright fixtures", "mock this API request", "add visual regression checks", or "review these E2E tests".
---

# Reliable Playwright E2E Tests and Flake Fixes

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →