Skip to content
Skillpedia
Testing280k Β· #176

e2e-testing

What it does

This guide teaches how to create automatic tests to check if a website or application works as expected. It shows how to organize tests, how to make code interact with page elements (like buttons and text fields), and how to handle tests that sometimes fail.

When to use it

  • βœ“When creating tests to verify a website is functioning correctly.
  • βœ“When organizing test code to make it easier to understand.
  • βœ“When trying to fix tests that fail intermittently (flaky tests).

Skill link

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/e2e-testing/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/e2e-testing/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œHow can I structure my end-to-end tests using Playwright?”

5 new skills a week. 1 minute to read.

How it works

It uses a structure called 'Page Object Model' where each page of the website has its own code 'object'. This helps keep the test code clean and organized. It also shows how to configure the testing environment and integrate tests into continuous integration (CI/CD) processes.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

E2E Testing Patterns

Comprehensive Playwright patterns for building stable, fast, and maintainable E2E test suites.

Test File Organization

tests/
β”œβ”€β”€ e2e/
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ login.spec.ts
β”‚   β”‚   β”œβ”€β”€ logout.spec.ts
β”‚   β”‚   └── register.spec.ts
β”‚   β”œβ”€β”€ features/
β”‚   β”‚   β”œβ”€β”€ browse.spec.ts
β”‚   β”‚   β”œβ”€β”€ search.spec.ts
β”‚   β”‚   └── create.spec.ts
β”‚   └── api/
β”‚       └── endpoints.spec.ts
β”œβ”€β”€ fixtures/
β”‚   β”œβ”€β”€ auth.ts
β”‚   └── data.ts
└── playwright.config.ts

Page Object Model (POM)

import { Page, Locator } from '@playwright/test'

export class ItemsPage {
  readonly page: Page
  readonly searchInput: Locator
  readonly itemCards: Locator
  readonly createButton: Locator

  constructor(page: Page) {
    this.page = page
    this.searchInput = page.locator('[data-testid="search-input"]')
    this.itemCards = page.locator('[data-testid="item-card"]')
    this.createButton = page.locator('[data-testid="create-btn"]')
  }

  async goto() {
    await this.page.goto('/items')
    await this.page.waitForLoadState('networkidle')
  }

  async search(query: string) {
    await this.searchInput.fill(query)
    await this.page.waitForResponse(resp => resp.url().includes('/api/search'))
    await this.page.waitForLoadState('networkidle')
  }

  async getItemCount() {
    return await this.itemCards.count()
  }
}

Test Structure

import { test, expect } from '@playwright/test'
import { ItemsPage } from '../../pages/ItemsPage'

test.describe('Item Search', () => {
  let itemsPage: ItemsPage

  test.beforeEach(async ({ page }) => {
    itemsPage = new ItemsPage(page)
    await itemsPage.goto()
  })

  test('should search by keyword', async ({ page }) => {
    await itemsPage.search('test')

    const count = await itemsPage.getItemCount()
    expect(count).toBeGreaterThan(0)

    await expect(itemsPage.itemCards.first()).toContainText(/test/i)
    await page.screenshot({ path: 'artifacts/search-results.png' })
  })

  test('should handle no results', async ({ page }) => {
    await itemsPage.search('xyznonexistent123')

    await expect(page.locator('[data-testid="no-results"]')).toBeVisible()
    expect(await itemsPage.getItemCount()).toBe(0)
  })
})

Playwright Configuration

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 ? 1 : undefined,
  reporter: [
    ['html', { outputFolder: 'playwright-report' }],
    ['junit', { outputFile: 'playwright-results.xml' }],
    ['json', { outputFile: 'playwright-results.json' }]
  ],
  use: {
    baseURL: process.env.BASE_URL || 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
    actionTimeout: 10000,
    navigationTimeout: 30000,
  },
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
    { name: 'webkit', use: { ...devices['Desktop Safari'] } },
    { name: 'mobile-chrome', use: { ...devices['Pixel 5'] } },
  ],
  webServer: {
    command: 'npm run dev',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 120000,
  },
})

Flaky Test Patterns

Quarantine

test('flaky: complex search', async ({ page }) => {
  test.fixme(true, 'Flaky - Issue #123')
  // test code...
})

test('conditional skip', async ({ page }) => {
  test.skip(process.env.CI, 'Flaky in CI - Issue #123')
  // test code...
})

Identify Flakiness

npx playwright test tests/search.spec.ts --repeat-each=10
npx playwright test tests/search.spec.ts --retries=3

Common Causes & Fixes

Race conditions:

// Bad: assumes element is ready
await page.click('[data-testid="button"]')

// Good: auto-wait locator
await page.locator('[data-testid="button"]').click()

Network timing:

// Bad: arbitrary timeout
await page.waitForTimeout(5000)

// Good: wait for specific condition
await page.waitForResponse(resp => resp.url().includes('/api/data'))

Animation timing:

// Bad: click during animation
await page.click('[data-testid="menu-item"]')

// Good: wait for stability
await page.locator('[data-testid="menu-item"]').waitFor({ state: 'visible' })

…
FAQ

What are end-to-end (E2E) tests?

These are tests that simulate a complete user experience from start to finish, interacting with the graphical interface as a real user would.

What is the Page Object Model (POM)?

It's a design pattern where each page of your website has a corresponding class in your test code. This makes the code more reusable and easier to maintain.

How does Playwright handle tests that fail randomly (flaky tests)?

Playwright offers strategies like 'quarantine' (isolating unstable tests) and tools to identify common causes of failures, such as timing issues (race conditions) or animations.

Details

Original description by the author

Playwright E2E testing patterns, Page Object Model, configuration, CI/CD integration, artifact management, and flaky test strategies. Use when writing Playwright tests, structuring page objects, or fixing flaky E2E runs in CI.

repo: affaan-m/ECC

Popularity

GitHub stars
280k
Ranking position
#176
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills