P

Claude Prompt for Creating E2E Tests

End-to-end (E2E) tests are essential to ensure your application works correctly from the end user's perspective. However, writing them is often time-consuming and repetitive: you need to simulate complete user journeys, manage selectors, async waits, and UI state assertions. Claude excels at this task by generating structured, maintainable E2E tests covering both nominal and edge cases. By providing your application context — tech stack, test framework, page structure — Claude produces test suites ready to run with Playwright, Cypress, or any other tool. It understands best practices like using data-testid, the Page Object Model pattern, and handling loading states. Whether starting from scratch or extending existing coverage, Claude transforms a functional description into robust tests in seconds, letting you focus on business logic rather than technical plumbing.

The prompt

Claude

You are a senior QA engineer specialized in end-to-end testing. Generate a complete E2E test suite for the following feature:

Application: [Describe your application and its tech stack]
Test framework: [PLAYWRIGHT / CYPRESS / other]
Feature to test: [Describe the user journey]
Base URL: [Local or staging URL]

For each test, apply these rules:

  1. Use robust selectors (data-testid first, then ARIA roles, never fragile CSS selectors)
  2. Implement the Page Object Model pattern for reusability
  3. Explicitly handle async waits (wait for elements to be visible before interacting)
  4. Cover the happy path, error cases (invalid form, network timeout), and edge cases (empty fields, special characters)
  5. Add comments explaining the tested business logic
  6. Isolate each test (no test dependencies, clean setup/teardown)
  7. Name each test with the format: "should [expected action] when [condition]"

Generate the complete code with imports, configuration, page objects, and test files.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why it works

This prompt works because it assigns Claude a precise expert role (senior QA engineer), activating its specialized testing knowledge. The seven numbered rules act as structuring constraints that eliminate common anti-patterns (fragile selectors, coupled tests, weak assertions). By explicitly requesting technical context (framework, stack, URL), the prompt forces a response tailored to the real environment rather than generic code.

Expected result

You will get a complete and organized E2E test suite: Page Object files encapsulating interactions with each page, test files covering the happy path and error cases, and a basic configuration for the chosen framework. Each test will be descriptively named, isolated from others, and accompanied by comments explaining the business scenario being verified.

Variants by level

FAQ

Which E2E test framework does Claude handle best?
Claude masters all major frameworks — Playwright, Cypress, Selenium, and Puppeteer — but delivers the best results with Playwright and Cypress due to abundant training data. Playwright is recommended for modern projects as Claude naturally generates code using its advanced features: auto-waiting, ARIA role selectors, and multi-browser execution. Always specify your framework in the prompt to get idiomatic rather than generic code.
How can I make Claude generate tests that don't break with every UI change?
The key is to instruct Claude on the selector strategy in your prompt. Explicitly ask to use data-testid attributes rather than CSS or XPath selectors tied to the DOM structure. You can also provide your existing naming convention (e.g., data-testid="login-submit-btn") for consistency. The Page Object Model, required in intermediate and advanced variants, centralizes selectors in one place, limiting cascade changes when the UI evolves.
Can Claude generate E2E tests from a user story or a mockup?
Yes, and this is one of its strengths. You can paste a Jira user story, a functional specification, or even describe a mockup in natural language, and Claude will deduce the paths to test. For visual mockups, use Claude's multimodal capability by attaching a screenshot: it will identify interactive elements, forms, and navigation flows to generate corresponding tests. The more precise your description (form fields, expected error messages, redirects), the more faithful the generated tests will be to the desired behavior.

Related prompts

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 4800+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More prompts to explore

Go further

Get new prompts every week

Join our newsletter.