Setup Instructions
Three prerequisites stand between you and generated specs: the MCP server, a running app, and a working directory that follows your project's test conventions.
Register the Playwright MCP server with Claude Code so it can drive a real browser against your app.
Step 1claude mcp add playwright npx @playwright/mcp@latest
Playwright MCP Guide
Playwright MCP gives Claude Code a real, controllable browser. Use it to explore the running application, record accurate selectors, and surface gaps in page objects before any spec is written.
Exploration workflow
- Ask Claude Code to open the app's base URL via Playwright MCP.
- Walk through each key user flow, capturing routes as you navigate.
- For every interactive element, note its role, accessible name, and any test id.
- Cross-reference existing page objects against what was found on the live DOM.
- List any elements missing accessible names or data-testid attributes.
Selector examples
page.getByTestId('submit-order-button')PreferStable, explicit test hook
page.getByRole('button', { name: 'Add to Cart' })PreferAccessible name + role, resilient to styling changes
page.locator('.btn.btn-primary.mt-2')AvoidFragile: tied to CSS classes that change with styling
Page object pattern
export class CheckoutPage {
constructor(private page: Page) {}
readonly submitButton = this.page.getByTestId('submit-order-button');
readonly emailInput = this.page.getByLabel('Email address');
async submitOrder() {
await this.submitButton.click();
}
}Common gaps to flag
- Icon-only buttons with no accessible label
- Dynamically rendered rows/cards with no stable identifier
- Modals and toasts that unmount before assertions can run
- Form fields without associated labels
Best practices
Prompt Template
Every mint-prompt run starts from this template. Fill in the four required fields, then hand the whole block to Claude Code.
Application URL: <http://localhost:PORT>
Key user flows:
- <flow 1: short description>
- <flow 2: short description>
Page objects:
- <PageObjectName>: <selectors / route>
Test scenarios to cover:
- Happy path: <describe>
- Validation / error case: <describe>
- State-dependent branch: <describe>
Instructions:
Explore the app with Playwright MCP, confirm the details above against the live DOM,
flag any missing test hooks, then write and run specs until they pass.Required fields
App Details Workflow
Before generation can succeed, the prompt needs an accurate picture of your application. Work through each field in order.
Application URL
The local base URL where the app is currently running β no login is required to reach it.
Accessible routes
List each route explored via Playwright MCP, including any nested or protected-but-loginless pages.
Key user flows
Describe the journeys worth testing, in the order a real user would perform them.
Page object mapping
Map each flow's interactive elements to selectors, preferring roles, labels, and test ids.
Validation checklist
Spec Generation
With the prompt filled in and the Playwright MCP server registered, generation happens directly inside Claude Code.
1. Open Claude Code in your project
Start Claude Code from your project root so it can read existing specs and page objects.
terminalcd your-project claude2. Paste the filled prompt
Paste your completed prompt template directly into the conversation.
3. Monitor generation
Claude Code will use Playwright MCP to explore the app live, confirm selectors, then write spec and page object files. Watch the tool calls to confirm it is exploring before writing.
4. Review the output
Check the generated spec for accurate selectors, meaningful assertions, and coverage of the scenarios you listed.
e2e/checkout.spec.tstest('guest can complete checkout', async ({ page }) => { const cart = new CartPage(page); await cart.goto(); await cart.addItem('sku-123'); await cart.checkoutButton.click(); await expect(page.getByText('Order confirmed')).toBeVisible(); });
Troubleshooting
Reporting Results
Once specs are generated, run them for real and turn the outcome into a report your team can act on.
Run the specs
npx playwright test e2e/checkout.spec.tsInterpret the output
- Green checks confirm the scenario passed against the live DOM
- Failures print the exact selector and expectation that did not match
- Flaky retries usually point to timing or unstable selectors, not broken features
Report template
## Test Run Summary
Files created/changed:
- e2e/checkout.spec.ts (new)
- page-objects/CartPage.ts (extended: added checkoutButton)
Page objects extended:
- CartPage: added checkoutButton, emptyCartMessage
data-testid gaps flagged:
- Checkout confirmation banner has no accessible name
Result: 6 passed, 0 failedBefore you call it done
- All new specs pass locally
- Page object changes are committed alongside specs
- Flagged data-testid gaps are shared with the team
- Report summarizes files changed and final pass/fail status
Frequently Asked Questions
Register the Playwright MCP server, make sure your app is running locally, then open Claude Code from your project root. See Setup Instructions above.
See Setup Instructions β

No comments yet. Be the first!