Testing / Playwright Interview questions
How do you use codegen in Playwright?
codegen is a CLI tool that opens a real browser alongside the Inspector, records your clicks, typing, and navigation, and writes them out as working test code in real time.
npx playwright codegen https://example.com
As you interact with the page, Playwright picks resilient locators (preferring role and text-based ones) for each element you touch, and the generated script updates live in a side panel that you can copy directly into a test file.
It's best used for quickly scaffolding a first draft of a test or exploring which locator Playwright would choose for a tricky element, rather than as the final, polished version of a test - generated scripts usually still need assertions and cleanup added by hand.
More Related questions...