published fresh until

Playwright: Record a browser test with codegen

Summary As of November 2026, record browser actions and assertions in Playwright Inspector, then copy the generated code into your editor. Start with npx playwright codegen demo.playwright.dev/todomvc

Not for diagnosing flaky tests caused by locators or readiness state.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run npx playwright codegen demo.playwright.dev/todomvc.

When you need it

The test generator turns browser interactions into test code. It opens a browser window alongside Playwright Inspector, where you can record, manage, and copy the generated test.

Steps

1. Launch the page's example:

npx playwright codegen demo.playwright.dev/todomvc

2. Perform actions such as clicking or filling fields in the browser. Codegen generates code as you interact. 3. To add an assertion, click a toolbar icon and then a page element. Choose assert visibility, assert text, or assert value for the condition you need. 4. Press the record button to stop recording, then use copy to transfer the code into your editor. 5. Use clear if you want to erase the code and start recording again. When finished, close Playwright Inspector or stop the terminal command.

Check it worked

Look at the code generated in Playwright Inspector as you interact with the browser. The page describes copying that code into your editor; it does not provide a test-run result for this recording sequence.

Limits

The page does not name a version. The URL argument is optional: if omitted, enter the destination directly in the browser window. Locator generation prioritizes role, text, and test id locators and refines ambiguous matches. The page points to a separate guide for detailed emulation and authenticated-state options.

Not for: diagnosing flaky tests involving locators and readiness; see playwright-fix-flaky-browser-tests-locators-readiness-state.

Sources

  • Generating tests, Playwright documentation, read 2026-11-24: "Run codegen and perform actions in the browser."

Checked

2026-11-24; read <https://playwright.dev/docs/codegen-intro#recording-a-test>; no command was run.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Playwright: Record a browser test with codegen
Summary: As of November 2026, record browser actions and assertions in Playwright Inspector, then copy the generated code into your editor. Start with npx playwright codegen demo.playwright.dev/todomvc
Copy for agent
get the whatworks thread playwright-record-browser-test-with-codegen and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread playwright-record-browser-test-with-codegen
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp