P
💻DeveloppementIntermediateClaude

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: simulating complete user journeys, handling selectors, async waits, and UI state assertions. Claude excels at this task by generating structured, maintainable E2E tests covering both happy paths and edge cases. By providing context about your application — tech stack, test framework, page structure — Claude produces ready-to-run test suites for Playwright, Cypress, or other tools. It understands best practices like data-testid usage, the Page Object Model pattern, and loading state management. Whether starting from scratch or supplementing existing coverage, Claude transforms a functional description into robust tests in seconds, letting you focus on business logic rather than technical plumbing.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

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 preferred, then ARIA roles, never fragile CSS selectors)
  2. Implement the Page Object Model pattern for reusability
  3. Explicitly handle async expectations (wait for visible elements 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 business logic being tested
  6. Isolate each test (no test interdependence, clean setup/teardown)
  7. Name each test with the format: "should [expected action] when [condition]"

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

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

This prompt works because it assigns Claude a precise expert role (senior QA engineer), activating specialized testing knowledge. The seven numbered rules act as structural 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.

Use Cases

Create E2E Tests

Variants

Expected Output

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

Frequently Asked Questions

Which E2E testing framework does Claude handle best?

Claude excels with all major frameworks — Playwright, Cypress, Selenium, and Puppeteer — but produces the best results with Playwright and Cypress due to the wealth of training data. Playwright is recommended for modern projects because 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 code rather than generic output.

How can I get Claude to generate tests that don’t break with every UI change?

The key is to instruct Claude on your selector strategy within the prompt. Explicitly ask it to use data-testid attributes instead of CSS or XPath selectors tied to the DOM structure. You can also provide your existing naming convention (e.g., data-testid="login-submit-btn") so it stays consistent. The Page Object Model pattern, requested in the intermediate and advanced variants, centralizes selectors in one place, preventing cascading changes when the interface evolves.

Can Claude generate E2E tests from a user story or mockup?

Yes, and that’s 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, leverage 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 closely the generated tests will match the intended behavior.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementIntermediateAll AIs

Generate Mocks and Fixtures for Your Automated Tests

A prompt to automatically generate realistic mocks, stubs and data fixtures adapted to your test framework and use cases.

091
💻DeveloppementIntermediateAll AIs

Automatically Generate Unit Tests with AI

Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.

0223
💻DeveloppementIntermediateGemini

Create a Python Automation Script

Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.

24239
💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

40233