How to Make Playwright CLI Write UI Tests For You
Here is the full workflow that turns Playwright CLI + an AI coding agent into a system that can write UI tests for you. It works with Cursor, Claude Code, Codex, or any agent you have. โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ ๐ข ๐๐ก๐ ๐๐ง๐ข๐ฏ๐๐ซ๐ฌ๐๐ฅ ๐๐จ๐ซ๐ค๐๐ฅ๐จ๐ฐ โค Step 1. Explore the test case with Playwright CLI You give the agent a real test case with the steps and validations: โ What user flow to cover โ What URL to start from โ What success looks like โ What data or credentials to use (or where to find them in the repo) The agent uses Playwright CLI to walk through that flow in the browser: โ `open` the starting page โ `snapshot` to read what is on screen โ `click`, `fill`, and navigate step by step โ `snapshot` again after each meaningful action The Agent is exploring the app the same way a human tester would, but faster, and with structured output, a.k.a it generates a file with it's findings. โค Step 2. You review. When exploration finishes, the Agent should produce a short exploration document. Something you can read and review. It should include: โ Pages visited and the order of steps โ Locators or element refs that worked โ Form fields, buttons, and links involved โ Assertions the Agent observed (visible text, URL changes, success messages) โ Anything ambiguous or blocked (login wall, captcha, missing test data) ๐๐จ๐ฎ ๐ซ๐๐ฏ๐ข๐๐ฐ ๐ญ๐ก๐ข๐ฌ ๐๐๐๐จ๐ซ๐ ๐๐ง๐ฒ ๐ญ๐๐ฌ๐ญ ๐๐จ๐๐ ๐ข๐ฌ ๐ฐ๐ซ๐ข๐ญ๐ญ๐๐ง. โค Step 3. The Agent generates UI tests Now the agent writes code. It uses two inputs: 1. The exploration document from Step 2 2. Your existing test framework. Folder structure, page objects, fixtures, naming conventions, helper methods Playwright CLI does not replace your framework. It feeds facts into it. Same workflow whether you use Playwright Test, Selenium, Cypress, or something else. The exploration layer is shared. The test code layer is yours. โค Step 4. The Agent runs the tests. The agent runs the new test (or the relevant suite). If it passes โ> done. If it fails โ> the agent goes back to Playwright CLI: