-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Feature]: ( CodeGen ) AI-powered test generation with network capture and prompt exportΒ #39847
Description
π Feature Request
Bridge playwright codegen with external AI tools by capturing the full recording context β user actions, network requests, and page state β and exporting it as a structured prompt that any AI assistant can use to generate production-ready Playwright tests.
Today, playwright codegen produces basic recorded code, but developers still spend significant time manually adding assertions, handling API responses, structuring test data cleanup, and following best practices. Meanwhile, AI tools like Claude Code, Cursor, and ChatGPT can generate excellent test files β if given the right context about what happened in the browser.
This feature would add an opt-in --ai-codegen flag that captures everything the recorder knows and makes it available to AI tools, without changing any default behavior.
Example
# Record with AI context capture enabled
npx playwright codegen --ai-codegen https://myapp.comWorkflow 1 β Copy/paste to any AI tool:
- Run codegen with
--ai-codegen, interact with the app - Click "Generate Test" β a structured prompt is copied to clipboard
- Paste into Claude Code, Cursor, ChatGPT, or any AI tool
- AI generates a complete test file with assertions, API mocking, and data cleanup
Workflow 2 β AI reads the session directly via MCP:
- Run codegen with
--ai-codegen, interact with the app - Tell your AI assistant: "there's a codegen session running, write the test"
- AI reads the live session via a new
recorder_get_sessionMCP tool - AI generates the test β no copy/paste needed
The prompt would include:
- Recorded user actions with timing
- Network requests classified by relevance (API calls vs. page loads vs. noise)
- Sensitive data automatically redacted (passwords, tokens, credit cards)
- Playwright best practices and data cleanup instructions
Motivation
playwright codegen captures what happened but not why it matters. The recorder knows about clicks, navigations, and form fills β but it doesn't capture the API calls those actions triggered, the response data that should be asserted on, or the test data that should be cleaned up. Developers bridge this gap manually today.
AI tools are already great at generating structured test code, but they lack context about the actual browser session. This feature closes that gap by making the recorder's full knowledge available as AI-consumable context.
Key benefits:
- Works with any AI tool β clipboard export means no vendor lock-in
- MCP integration β AI assistants that support MCP can read sessions directly, enabling a fully conversational workflow
- Zero impact on existing users β everything is gated behind
--ai-codegen, default codegen behavior is completely unchanged - No new dependencies β builds entirely on existing Playwright internals