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