Generate Tests by Recording Browser Actions
Use Playwright Codegen to record user interactions in the browser and automatically generate test scripts with proper locators.
Prerequisites
- -Playwright installed
- -A running web application
Steps
Launch the code generator
Open a browser with the codegen recorder attached.
Interact with the page normally. Every click, type, and navigation is recorded as test code in real time.
Generate code for a specific viewport
Record tests at a specific screen size for responsive testing.
Record with authentication state
Start codegen with a saved authentication state to skip login flows.
First save auth state with 'npx playwright codegen --save-storage=auth.json' after logging in manually.
Use the locator picker
Launch the inspector to find robust locators for page elements.
Generate tests in a specific language
Output test code in your preferred language.
Supported targets include playwright-test (TypeScript), python-pytest, java-junit, and csharp-mstest.
Full Script
FAQ
Discussion
Loading comments...