/playwright-e2e:fixture-generationfrom playwright-e2e
Create custom Playwright fixtures using test.extend<T>. Covers typed fixture definitions, auth state fixtures with storageState, test data fixtures, teardown cleanup, and global auth setup in auth.setup.ts.
Ships in playwright-e2e. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
test.extend<T>Extend the base Playwright test object with typed custom fixtures. Export the extended test and expect from a single barrel file so all specs import from one location.
// tests/e2e/fixtures/test.ts
import { test as base, expect } from '@playwright/test';
import { LoginPage } from '../pages/login.page';
// Define the shape of your custom fixtures
type CustomFixtures = {
loginPage: LoginPage;
testUser: { email: string; password: string };
};
export const test = base.extend<CustomFixtures>({
// Fixture: LoginPage instance (scoped per test)
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await use(loginPage);
// teardown: nothing needed — page is discarded after each test
},
// Fixture: test user credentials from environment
testUser: async ({}, use) => {
const user = {
email: process.env.TEST_USER_EMAIL ?? '[email protected]',
password: process.env.TEST_USER_PASSWORD ?? 'testpassword',
};
await use(user);
},
});
// Re-export expect so specs only need one import
export { expect };
Authenticated tests must not perform login steps inline. Instead, load saved auth state via a fixture:
// tests/e2e/fixtures/test.ts (extended with auth)
import { test as base, expect, BrowserContext } from '@playwright/test';
import path from 'path';
const AUTH_FILE = path.join(__dirname, '../.auth/user.json');
type AuthFixtures = {
authenticatedContext: BrowserContext;
};
export const test = base.extend<AuthFixtures>({
authenticatedContext: async ({ browser }, use) => {
const context = await browser.newContext({ storageState: AUTH_FILE });
await use(context);
await context.close();
},
});
export { expect };
Use fixtures to provide isolated, typed test data. Clean up in the teardown phase (after use):
type TestDataFixtures = {
createdOrder: { id: string; total: number };
};
export const test = base.extend<TestDataFixtures>({
createdOrder: async ({ request }, use) => {
// Setup: create test data via API
const response = await request.post('/api/orders', {
data: { product: 'widget', quantity: 1 },
});
const order = await response.json();
await use(order);
// Teardown: remove test data after each test
await request.delete(`/api/orders/${order.id}`);
},
});
auth.setup.tsGenerate a global setup file that logs in once and saves storageState to disk. Reference it in playwright.config.ts as a setup project so it runs before the main test suite.
// tests/e2e/auth.setup.ts
import { test as setup, expect } from '@playwright/test';
import path from 'path';
const AUTH_FILE = path.join(__dirname, '.auth/user.json');
setup('authenticate', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill(process.env.TEST_USER_EMAIL!);
await page.getByLabel('Password').fill(process.env.TEST_USER_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until auth is confirmed before saving state
await expect(page).toHaveURL('/dashboard');
await page.context().storageState({ path: AUTH_FILE });
});
Wire it into playwright.config.ts:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{ name: 'setup', testMatch: '**/auth.setup.ts' },
{
name: 'chromium',
use: {
storageState: 'tests/e2e/.auth/user.json',
},
dependencies: ['setup'],
},
],
});
tests/e2e/
fixtures/
test.ts ← main extended test + expect export
auth.ts ← auth-specific fixtures (optional split)
test-data.ts ← test data fixtures (optional split)
.auth/
user.json ← saved storageState (git-ignored)
auth.setup.ts ← global setup project
Add tests/e2e/.auth/ to .gitignore to prevent committing credentials.
test and expect together from fixtures/test.ts.test block — use storageState via a fixture.await use(...) in the same fixture function.test scope (default) for per-test isolation, worker scope for expensive shared resources.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
7 skills in this plugin
/e2e-assertionsWeb-first Playwright assertions with built-in auto-waiting. Covers the full assertion API, soft assertions for non-critical checks, negation, custom failure messages, and anti-patterns to avoid./e2e-project-structureScaffold the E2E directory layout, establish file naming conventions, adapt to monorepo directoryMapping, and support both the page-object and co-located test patterns./e2e-selectorsFramework-aware locator strategy for Playwright. Defines locator priority, per-framework selector tables for React, Angular, Vue, and plain HTML, anti-patterns to avoid, and DO/DON'T examples./e2e-test-generationGenerate E2E spec files from natural language descriptions, URLs, or user flow descriptions. Produces fully-typed .spec.ts files with test.describe/test blocks, framework-aware selectors, auth handling via storageState, and correct import paths./e2e-testingRun the E2E test suite via the Playwright coding agent core test-runner with E2E-specific flags. Captures traces and videos on first retry, parses the HTML report, extracts trace viewer URLs, and categorizes failures./page-object-generationGenerate Page Object Model (POM) classes with typed locators as getters, actions as async methods, and a shared base page class. One POM per page or major section.npx claudepluginhub gagandeepp/software-agent-teams --plugin playwright-e2e