Write a Cypress E2E Test for a Complete User Workflow

Create a robust Cypress E2E test covering a full user workflow with API stubbing, custom commands, and best practices.

๐Ÿ“ The Prompt

Write a Cypress end-to-end test spec that validates the complete [WORKFLOW_NAME] user workflow on [APPLICATION_TYPE] (e.g., e-commerce checkout, user registration, dashboard CRUD). The application runs at [BASE_URL] and uses [AUTH_METHOD] for authentication. Workflow steps to test: [LIST_WORKFLOW_STEPS_IN_ORDER] Generate the test spec with these components: 1. **Test Setup (before/beforeEach)**: - Seed test data using cy.request() to call [API_ENDPOINT] or use cy.task() for database seeding - Implement programmatic login via API to skip UI login (store token in localStorage/cookies) - Set viewport to [VIEWPORT_SIZE] and configure baseUrl 2. **Custom Commands**: Define reusable commands in commands.js for: - Login: Cypress.Commands.add('login', ...) - A domain-specific action: [CUSTOM_COMMAND_DESCRIPTION] - Selecting elements using data-testid attributes following the pattern [data-testid="[ELEMENT_PATTERN]"] 3. **Test Cases** (within describe/it blocks): - **Happy Path**: Walk through the entire workflow asserting each page transition, form submission, and success state - **Validation Test**: Submit forms with invalid data and assert error messages appear for [REQUIRED_FIELDS] - **Edge Case**: Test behavior when [EDGE_CASE_SCENARIO] (e.g., network timeout, empty state, duplicate submission) - **Responsive Check**: Verify critical elements at mobile viewport (375x667) 4. **Assertions & Waits**: - Use cy.intercept() to stub or spy on [API_CALLS] and alias them with .as() - Wait for API responses with cy.wait('@alias') before asserting DOM changes - Assert URL changes with cy.url().should('include', '/[EXPECTED_PATH]') - Verify toast notifications, modals, or redirect behavior 5. **Cleanup (after)**: Remove test data via API calls or cy.task() Use best practices: no cy.wait(ms), no hard-coded selectors like .btn-primary, and no conditional testing. Include comments explaining the purpose of each intercept and assertion.

๐Ÿ’ก Tips for Better Results

List every step of the user workflow in order so the AI generates a realistic page-by-page test flow. Use data-testid attributes in your app โ€” mention the naming convention so generated selectors match. Specify which API calls the workflow triggers so cy.intercept() stubs are accurate.

๐ŸŽฏ Use Cases

Frontend developers and QA engineers use this when automating critical user journeys to catch UI regressions and verify end-to-end functionality before releases.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.