microsoft / microsoft/playwright

[Feature]: ( CodeGen ) AI-powered test generation with network capture and prompt export

Open
#39,847 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

P3-collecting-feedback
Dominant language
TypeScript
Stars
96.3k
Forks
6.5k
Avg merge
1d 6h
Merged PRs (30d)
180

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

```bash
# Record with AI context capture enabled
npx playwright codegen --ai-codegen https://myapp.com
```

**Workflow 1 — Copy/paste to any AI tool:**
1. Run codegen with `--ai-codegen`, interact with the app
2. Click "Generate Test" — a structured prompt is copied to clipboard
3. Paste into Claude Code, Cursor, ChatGPT, or any AI tool
4. AI generates a complete test file with assertions, API mocking, and data cleanup

**Workflow 2 — AI reads the session directly via MCP:**
1. Run codegen with `--ai-codegen`, interact with the app
2. Tell your AI assistant: *"there's a codegen session running, write the test"*
3. AI reads the live session via a new `recorder_get_session` MCP tool
4. 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the `playwright codegen` recorder entry point and reviewing the existing MCP integration. Define the scope for the opt-in `--ai-codegen` session capture, structured prompt or clipboard export, and `recorder_get_session` workflow. Done means the design covers actions, network and page-state context, sensitive-data redaction, and unchanged default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, testing-qa, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.