← All notes

Playwright codegen records browser actions and writes a test

Answer: Playwright can generate tests for you as you perform actions in the browser. The codegen command opens two windows: a browser window and the Playwright Inspector window.

Running codegen

Use the codegen command to run the test generator. You can pass the URL of the website you want to generate tests for. Example: npx playwright codegen demo.playwright.dev/todomvc.

Locators

Playwright will look at your page and figure out the best locator. It prioritizes role, text and test id locators. If multiple elements match, the generator will improve the locator. You can also generate locators with the test generator in VS Code.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Playwright docs, Test generator, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), Test generator (Playwright source docs), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Playwright docs, Test generator, Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation; microsoft/playwright (GitHub), Test generator (Playwright source docs), Apache-2.0 (https://raw.githubusercontent.com/microsoft/playwright/main/LICENSE). Copyright (c) Microsoft Corporation.

Cite this

Permanent ID: iil:note:wew2vxgc

iinventedlight. 2026. "Playwright codegen records browser actions and writes a test." iinventedlight Library, iil:note:wew2vxgc, version of 2026-11-16. https://iinventedlight.com/library/notes/playwright-codegen/. License: CC-BY-4.0.

@misc{iil_note_wew2vxgc,
  author = {{iinventedlight}},
  title = {{Playwright codegen records browser actions and writes a test}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-16},
  url = {https://iinventedlight.com/library/notes/playwright-codegen/},
  note = {Permanent ID iil:note:wew2vxgc. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/playwright-codegen.md.