← All use cases

中文

Building software · Claude Code

Have Claude Code explore your app and write Playwright tests

Idea + starter prompt, not run by us yet

For: Developers and testers who need end-to-end tests for a web app

Claude Code gets the Playwright MCP server and a saved test login. The prompt has three sections: facts about the setup, the user journey in everyday words, and fixed rules. Reading the running app through its accessibility tree, the agent drafts a test, executes it and repairs what breaks, including a strict mode locator error. Long journeys, shifting data, heavy branching and OAuth logins give it trouble.

Steps

  1. Add the Playwright MCP server and save a logged in session for a test account.
  2. Add the saved session folder to .gitignore before committing.
  3. Write your prompt in three parts: environment, scenario and rules.
  4. Review the test code and check it tests what you meant.
  5. Run it several times in a row to check for flaky results.

Starter prompt

Starter prompt. Change the [brackets] first.

Environment: my app runs at [URL] with a test account session saved in [session file]. Scenario: [describe the user journey in plain English]. Rules: use role or label based locators, no fixed waits, and keep the test in [test folder]. Explore the page, write the Playwright test, run it and fix failures. Do not use real customer data or change anything outside the test folder. Show me the final test code.

Original post: DEV · found via agentusecases.ai. Written up in our own words. We haven't run it, so test it on made-up data first.