How to use the Playwright Test Code Generator
- 1. Write the stepsOne per line, using the simple step language below the box.
- 2. Pick a languageTypeScript or JavaScript for @playwright/test, or Python for pytest-playwright.
- 3. GenerateCopy the test and the config, then run npx playwright test or pytest.
How the test is written
Each line of the box is one step. Actions are open, type, select, click, check, uncheck, hover and press; checks start with expect and cover the URL, title, visible text, visibility and field values. Selectors can be CSS, or text=, label=, placeholder=, testid= and role=, which survive design changes better than long CSS paths. Everything runs in your browser; nothing you enter is uploaded.
Selectors map to Playwright's recommended locators: getByRole, getByLabel, getByPlaceholder, getByText and getByTestId. Checks use web-first assertions such as toHaveURL and toBeVisible, which retry until they pass or time out, so you never need manual waits. The config sets your base URL, retries on CI and trace recording on the first retry.
Worked example
The sample steps open /login, fill the email by its label and the password by ID, click Log in, check the URL and the welcome text, then log out by test ID. In TypeScript that's a 13-line test. We ran the TypeScript, JavaScript and Python versions of a longer test with Playwright 1.63 against a local login page, and all three passed; the TypeScript also passes tsc --strict.
Tips
- Use
npx playwright codegento find a good locator, then put it into the steps here. - Run with
--uior--trace onto debug failures step by step. - Keep one behaviour per test; long flows are harder to debug.
Frequently asked questions
Does it support API testing?
This generator writes browser tests. For API cases, use our API test case generator.
Which Playwright version?
The code uses stable APIs available in all recent Playwright versions; we tested with 1.63.
Is the Playwright test generator free?
Yes. You can open the Playwright test generator and fill in everything without signing up. When you generate code for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.