QuickDevGuide

Home › Playwright

Code Generation — Playwright

Playwright's Codegen tool opens a browser window where you interact with your app. Every click, type, and navigation is recorded as test code in real-time. Generate Tests from Browser Interactions How Codegen Works Run codegen → Browser opens with your app + a code panel Interact → Click, type, navigate, select dropdowns Code appears → Real test code is generated live Copy/Save → Paste into your test file and customize Example Generated Output Locator Priority (Best to Worst) Priority Locator Example 1 Role page.getByRole('button', { name: 'Submit' }) 2 Label page.getByLabel('Email') 3 Text page.getByText('Welcome') 4 Test ID page.getByTestId('submit-btn') 5 CSS page.locator('.btn-primary') (less stable)

Key Takeaways