When should you use it?
- Agent-written tests keep breaking in CI
- You already use Playwright
- You can run the app locally or on staging
Not for: Unit testing; Apps you cannot log into with a test account
What do you need, and what do you get?
You need
- Node 20 or later
- A Playwright project
- A test user and stored login state
You get
- A test file built from real locators
- A scenario file in plain English
- Evidence the test passes on repeat runs
How does it work, step by step?
- Check prerequisitesConfirm Node, the agent and a Playwright config exist before starting.
- Register the browser serverConnect the Playwright MCP server so the agent can drive a real browser.
- Save login stateStore an authenticated session so tests skip the login wall.
- Describe the scenario plainlyWrite numbered steps in English, including expected results.
- Review and repeatRead the test twice, then rerun it back to back to expose flakiness.
The prompt
Our own prompt, inspired by Jakob Norlin and written to work in Claude Code. Values in lime are placeholders.
Using the Playwright browser tools, open [URL] with the saved login state. Follow this scenario: [numbered steps]. At each step, read the locator from the page itself, preferring roles and visible labels. Then write tests/[name].spec.ts and save the scenario as [name].md beside it. Run the test five times and report any failure.
Inspired by Jakob Norlin: How To Write Playwright tests in minutes with Playwright MCP and Claude Code. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.
What can go wrong?
- MCP commands change quickly; check the official repo if instructions drift.
- A test that passes once is not yet a good test.
Our take
Jakob Norlin's piece is clear, careful and focused on the real failure mode. Tests that guess selectors from source look fine on a developer's machine and break in CI when the DOM differs. Reading locators from the live rendered page closes that gap. The habit of keeping a plain-English scenario beside the test is worth adopting even without agents, because it documents intent for the next person. Use a dedicated test account with fake payment data, never a real card. Add the repeat run to CI for new tests during their first week so flaky ones surface before they waste everyone else's time. Do two review passes: one for whether the scenario matches product intent, one for whether the selectors are stable. Prefer role- and text-based locators over brittle CSS chains. Commit the scenario file next to the test so they stay in sync. Fail the build on new flaky tests rather than silencing them.
Where the time goes back: Tests built from what the browser actually renders break less often, saving debugging time after merges.
FAQ
Why do guessed selectors fail?
How many repeat runs?
Source and credit
Inspired by Jakob Norlin. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.
- Inspired by
- How To Write Playwright tests in minutes with Playwright MCP and Claude Code
- Creator
- Jakob Norlin
- Published on
- DEV Community (dev.to)
- Original date
- Oct 5, 2026
- License
- Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
- Originally for
- Claude Code
- AI dry run
- Oct 23, 2026: passed. Dry-run tested by our AI test agent on sample input. PASS: Gates held on desk check; no live sends or purchases.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails. - Verified
- Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.
Are you the creator? Claim or correct this page.