Codegen

Record a test

npx playwright codegen \
  https://playwright.dev

Records clicks and fills. Stop recording, then copy the test code from the Inspector. See test generator.

Choose output language

npx playwright codegen \
  --target=python \
  https://demo.playwright.dev/todomvc

Generates code. Choose the output language for the recorded steps. See codegen options.

Pick a locator

await page.pause()

Opens the Inspector. In a running script, use Pick Locator to copy a generated locator. See generating locators.

Emulate a device

npx playwright codegen \
  --device="iPhone 13" \
  playwright.dev

Records with a device. The device supplies its viewport and user agent to the recording. See emulation.

Reuse a login

npx playwright codegen \
  --save-storage=auth.json \
  https://github.com

Saves the login state. Cookies and local storage are stored after login; pass --load-storage=auth.json to resume that session, and keep the file private. See authenticated state.

0 Comments for this cheatsheet. Write yours!