All skills
asyrafhussin avatar

/e2e-playwright-testing

@c03e38f

End-to-end testing with Playwright for web applications. Use when writing E2E tests, browser automation, form submission testing, or user flow testing. Triggers on "playwright", "e2e test", "browser test", "end-to-end", "form flow testing", or test files in tests/e2e/.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/e2e-playwright-testing

This session only. Nothing lands on disk.

rulesauth-storage-state.md

≈949 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Reuse Authentication with Storage State

Impact: CRITICAL (eliminates login overhead and rate-limit failures)

Log in once per role in a setup project, save browser state to JSON files, and reuse via storageState in all tests. Never log in per-test.

Incorrect

// Bad: Logging in at the start of every test
test('dashboard shows data', async ({ page }) => {
    await page.goto('/login');
    await page.getByLabel('Email').fill('user@example.com');
    await page.locator('#password').fill('password');
    await page.getByRole('button', { name: 'Sign In' }).click();
    await page.waitForURL('**/dashboard');

    // Now the actual test...
    await expect(page.getByText('Welcome')).toBeVisible();
});

test('profile shows name', async ({ page }) => {
    // Same login repeated — slow, hits rate limits
    await page.goto('/login');
    await page.getByLabel('Email').fill('user@example.com');
    // ...
});

Problems:

  • Each test wastes 1-2 seconds on login
  • Login rate limits (429) block the entire suite after ~5 tests
  • Login failures cascade — every test fails, not just auth tests

Correct

// auth/auth.setup.js — runs once before all tests
import { test as setup, expect } from '@playwright/test';
import path from 'path';

const AUTH_DIR = path.join(import.meta.dirname, '..', '.auth');

const users = [
    { name: 'customer', file: 'customer.json', email: 'customer@example.com' },
    { name: 'admin', file: 'admin.json', email: 'admin@example.com' },
];

for (const user of users) {
    setup(`authenticate as ${user.name}`, async ({ page }) => {
        await page.goto('/login');
        await page.getByLabel('Email').fill(user.email);
        await page.locator('#password').fill('password');
        await page.getByRole('button', { name: 'Sign In' }).click();
        await page.waitForURL('**/dashboard');

        await page.context().storageState({ path: path.join(AUTH_DIR, user.file) });
    });
}
// fixtures/test.js — custom fixture for role-based auth
import { test as base } from '@playwright/test';
import path from 'path';

const AUTH_DIR = path.join(import.meta.dirname, '..', '.auth');

export const test = base.extend({
    role: ['customer', { option: true }],
    authedPage: async ({ browser, role }, use) => {
        const context = await browser.newContext({
            storageState: path.join(AUTH_DIR, `${role}.json`),
        });
        const page = await context.newPage();
        await use(page);
        await context.close();
    },
});
// specs/dashboard.spec.js — tests get pre-authenticated pages
import { test, expect } from '../fixtures/test.js';

test.describe('Dashboard', () => {
    test.use({ role: 'customer' });

    test('shows welcome message', async ({ authedPage: page }) => {
        await page.goto('/dashboard');
        await expect(page.getByText('Welcome')).toBeVisible();
    });
});
// playwright.config.js — setup project runs first
export default defineConfig({
    projects: [
        { name: 'auth-setup', testMatch: /auth\.setup\.js$/, testDir: './auth' },
        { name: 'chrome', use: { ...devices['Desktop Chrome'] }, dependencies: ['auth-setup'] },
    ],
});

Benefits:

  • Login happens once per role (3 logins for 90+ tests)
  • No rate-limit issues even with strict throttling
  • Each test starts instantly with pre-loaded cookies
  • Role switching is a simple test.use({ role: 'admin' })

Reference: Playwright Docs — Authentication

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive set of best practices and patterns for writing reliable end-to-end tests using Playwright. It focuses on locator strategies, authentication reuse, form handling, and test organization. No security issues were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at c03e38f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 6 months ago
Other metadata
metadata
{
  "author": "Agent Skills Contributors",
  "version": "1.0.0",
  "playwrightVersion": "1.50+",
  "nodeVersion": "18+"
}

README badge

README badge for asyrafhussin/agent-skills/e2e-playwright-testing