Skip to content
Back to skills

Playwright E2e

ASecurity

Expert-level Playwright testing instructions for AI coding agents. Focuses on robust, maintainable, flake-free browser automation.

  • 4 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 7, 2026
ai-agentsjavascripttypescriptpythongojavatestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned October 7, 2026

npx -y skills add romangalaxys10-spec/fable --skill playwright-e2e --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Playwright E2e?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Playwright E2e
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/romangalaxys10-spec-playwright-e2e/badge)](https://www.skillsdirectory.com/skills/romangalaxys10-spec-playwright-e2e)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: playwright-e2e
title: Playwright End-to-End Testing Patterns
category: Automation
testingTypes:
  - E2E
  - UI
  - Visual Regression
frameworks:
  - Playwright
languages:
  - TypeScript
  - JavaScript
  - Python
author: Pramod Dutta (QASkills.sh)
---

# Playwright E2E Testing Patterns

Expert-level Playwright testing instructions for AI coding agents. Focuses on robust, maintainable, flake-free browser automation.

## Core Mental Model

1. **Auto-Waiting Over Arbitrary Sleeps**:
   - 🚫 NEVER use `page.waitForTimeout()`, `time.sleep()`, or fixed delays. Arbitrary sleeps are the #1 cause of flaky tests.
   - βœ… Rely on Playwright's built-in auto-waiting (`click`, `fill`, `check` auto-wait for actionability).
   - βœ… Use web-first assertions: `await expect(locator).toBeVisible()`, `await expect(locator).toHaveText()`.

2. **User-Centric Locators**:
   - Order of locator preference:
     1. `page.getByRole('button', { name: 'Submit' })` (Accessible, mirrors real user actions)
     2. `page.getByLabel('Username')`
     3. `page.getByPlaceholder('Enter your email')`
     4. `page.getByText('Welcome back')`
     5. `page.getByTestId('checkout-btn')` (When role/label is ambiguous)
   - 🚫 NEVER use brittle XPath or deep CSS selectors (`div > div:nth-child(3) > span`).

3. **Page Object Model (POM) Discipline**:
   - Separate locator definitions and user interactions from test assertions.
   - Each Page Object encapsulates one cohesive page or modal.
   - Return clean action promises; perform assertions in the test spec, not inside the Page Object.

4. **Network Interception & Deterministic State**:
   - Use `page.route('**/api/v1/orders', async (route) => { ... })` to mock flaky third-party APIs.
   - Use `page.waitForResponse()` to synchronize on network calls rather than UI guesses.

## Pattern Implementation

```typescript
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';

test.describe('Authentication Flow', () => {
  test('User successfully logs in with valid credentials', async ({ page }) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await loginPage.login('developer@example.com', 'SecurePass123!');

    // Web-first assertion
    await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
    await expect(page).toHaveURL(/.*dashboard/);
  });

  test('Shows validation error when password is empty', async ({ page }) => {
    const loginPage = new LoginPage(page);
    await loginPage.goto();
    await loginPage.submitWithCredentials('developer@example.com', '');

    await expect(page.getByRole('alert')).toHaveText(/password is required/i);
  });
});
```

## Anti-Patterns to Avoid

- ❌ Hardcoding credentials or environment URLs. Use environment variables.
- ❌ Sharing state across tests. Every test must run in a clean browser context.
- ❌ Testing third-party services (Stripe, Google OAuth) directly in E2E runs; stub them with `page.route()`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.