Claude-skill-registry generate-e2e-test
Generate an end-to-end test for a given feature or user story. Use when the user asks to create E2E tests, automate workflows, test user flows, or convert manual workflows into Playwright tests. Leverages Playwright MCP to perform the workflow interactively before generating test code.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/generate-e2e-test" ~/.claude/skills/majiayu000-claude-skill-registry-generate-e2e-test && rm -rf "$T"
skills/data/generate-e2e-test/SKILL.mdGenerate E2E Test
This Skill converts workflow descriptions into working automated end-to-end tests by first performing the workflow step-by-step using Playwright MCP browser tools, then generating and refining test code based on the actual interaction.
Overview
Convert the following workflow description into working automated tests:
$ARGUMENTS
Process
1. Initial Setup
- Start Playwright MCP browser session using
to target URLbrowser_navigate - Ask the user to authenticate and perform any initialization steps if needed (there are likely already helper methods in the project test platform files for this)
- Take initial snapshot using
to understand page structure and confirm readiness to begin with the userbrowser_snapshot
2. Manual Workflow Execution
For each step in the described workflow:
Capture state: Use
browser_snapshot before each interaction to understand the current page structure
Perform action: Execute using appropriate MCP tools:
- Click buttons, links, or elementsbrowser_click
- Type text into fieldsbrowser_type
- Fill multiple form fields at oncebrowser_fill_form
- Select from dropdownsbrowser_select_option
- Press keyboard keysbrowser_press_key- Other browser tools as needed
Collect selectors:
- Primary: Note
values from accessibility snapshots (most stable)ref - Fallback: Use
with queries likebrowser_evaluate
if neededdocument.querySelector('[data-testid="..."]')
Verify outcomes: Use
browser_wait_for or snapshot to confirm expected results after each action
Document: Track successful selector patterns and interaction sequences for test generation
3. Generate Test Code
Read project conventions: Review
TESTING.md for:
- Test runner setup and syntax
- Available helper methods and fixtures
- Assertion patterns
- File naming and location conventions
Write test spec: Transform recorded workflow into test code using:
- Collected selectors (prefer stable attributes: data-testid, aria-label, role+name)
- Project's testing patterns from TESTING.md
- Appropriate waits and assertions
- Helper methods from
tests/e2e/utils/test-helpers.ts
File location: Place test in appropriate directory under
tests/e2e/ based on feature area:
- Super admin featurestests/e2e/admin/
- Authentication flowstests/e2e/auth/
- Client-specific featurestests/e2e/client/
- Dashboard pagestests/e2e/dashboard/
- Public pagestests/e2e/marketing/
- Workout featurestests/e2e/workouts/
4. Validate & Refine
Run test: Execute using project's test command from TESTING.md:
pnpm test:e2e:ai tests/e2e/your-test.spec.ts
Debug failures:
- If selector issues: Return to MCP browser, use
andbrowser_snapshot
to find better selectorsbrowser_evaluate - If timing issues: Add appropriate waits using
or similar helperswaitForElementWithRetry - If assertion failures: Verify expected values using MCP tools
Iterate: Repeat debugging until test passes consistently
Key MCP Tools Usage
Discovery:
(primary) - Get page structure and element informationbrowser_snapshot
(for complex queries) - Execute JavaScript to query DOMbrowser_evaluate
Actions:
- Click elementsbrowser_click
- Type textbrowser_type
- Fill multiple form fieldsbrowser_fill_form
- Select dropdown optionsbrowser_select_option
- Press keyboard keysbrowser_press_key
Validation:
- Wait for elements or conditionsbrowser_wait_for
tools - Verify element visibility, text, and valuesbrowser_verify_*
Debugging:
- Check console errorsbrowser_console_messages
- Inspect network activitybrowser_network_requests
- Capture visual statebrowser_take_screenshot
Best Practices
Selector Strategy
- Prefer accessibility-based selectors (role, aria-label) over fragile CSS
- Use test utilities like
,getByRole()
,getByText()
from PlaywrightgetByLabel() - Always verify selectors return only a single element to avoid strict mode violations
- Check if actions are in dropdown menus (look for "More actions" buttons)
Waiting and Timing
- Always wait for elements/text after navigation or async operations
- Use helper methods like
for robust waitingwaitForElementWithRetry() - For table data: Use
before interacting with table elementswaitForTableLoaded(page)
Test Structure
- Use fixtures from
for pre-configured test datatests/e2e/fixtures.ts - Test both happy path and error conditions when specified
- Scope selectors to specific containers to avoid matching toast notifications
- Clean up test data using protected email patterns (
)e2e-*@example.com
Navigation
- Use
helper instead ofnavigateToPage()
for reliable client-side routingpage.goto() - Wait for content-based conditions, not just
domcontentloaded
Examples
Simple Form Test
import { test, expect } from './fixtures' import { navigateToPage, expectToast } from './utils/test-helpers' test('user can create exercise', async ({ page, superAdminUser }) => { await navigateToPage(page, '/super-admin/exercises') await page.getByRole('button', { name: 'Add Exercise' }).click() await page.getByLabel('Name').fill('Bench Press') await page.getByLabel('Muscle Group').selectOption('Chest') await page.getByRole('button', { name: 'Save' }).click() await expectToast(page, 'Exercise created successfully') })
Workflow with Dropdown Menu
test('user can delete exercise', async ({ page, superAdminUser }) => { await navigateToPage(page, '/super-admin/exercises') // Open dropdown menu first const row = page.locator('tr').filter({ hasText: 'Bench Press' }) await row.locator('[aria-label*="More actions"]').click() // Then select delete action await page.getByRole('menuitem', { name: 'Delete' }).click() await page.getByRole('button', { name: 'Confirm' }).click() await expectToast(page, 'Exercise deleted successfully') })
Requirements
- Playwright MCP server must be running and connected
- Development server should be running at http://localhost:3000
- Project must have
and test utilities configuredTESTING.md
Troubleshooting
If tests fail:
- Read the AI Coding Agent Reporter output in
test-report-for-coding-agents/all-failures.md - Check console logs using
browser_console_messages - Inspect DOM structure with
browser_snapshot - Verify network requests with
browser_network_requests - Take screenshots at failure points with
browser_take_screenshot
If stuck debugging, ask a human to inspect the Playwright trace in
playwright-report/ which contains detailed execution information.