cypress-skill: Writing E2E and Component Tests in Agents Following Cypress Production Standards

Preface

When writing automation with Cypress, common issues are rarely about knowing “how to cy.visit”. Instead, problems usually involve mixing chained commands with async/await, hard-coding cy.wait(5000), using fragile class selectors, or encountering configuration mismatches between local environments and cloud/CI environments. Letting general LLMs generate test cases directly often leads to these exact same pitfalls.

This article introduces the cypress-skill maintained by TestMu AI in the LambdaTest agent-skills repository. This Skill encodes the execution goal judgment, directory conventions, anti-patterns, and validation checklists of senior QAs working with Cypress. When users mention Cypress, cy.*, E2E, or component testing, it guides the generation of JavaScript/TypeScript test cases that align closer to production habits, and distinguishes between local runs and TestMu AI (formerly LambdaTest) cloud execution paths.

What is this

cypress-skill is an Agent Skill oriented towards e2e-testing (SKILL.md metadata version 1.0, MIT license, author TestMu AI).

Its official description can be summarized as: Generating production-grade Cypress E2E and component tests in JavaScript or TypeScript; supporting both local execution and TestMu AI cloud.

Typical trigger words include: Cypress, cy., component test, E2E test, TestMu, LambdaTest, as well as specific command scenarios like cy.visit, cy.get, cy.intercept. This Skill is listed among the official TestMu AI Skills included in VoltAgent/awesome-agent-skills and can be used with tools supporting Agent Skills, such as Cursor, Claude Code, and Codex CLI (specific mounting paths depend on each tool’s documentation; the source code directory for this Skill is cypress-skill/ in the repository).

Core Features

Execution Goal (Local vs Cloud)

The Skill embeds a decision logic: When a user wants to “test / automate”, if they mention cloud, TestMu, LambdaTest, or cross-browser, it routes to TestMu AI cloud (via the cypress-cli plugin); if they mention locally, open, or headed, it routes to local npx cypress open. If the intent is unclear, it defaults to local and prompts for the cloud option.

Test Types & Directories

User Signal Type Conventional Directory
E2E, end-to-end, page URL E2E cypress/e2e/
component, React, Vue Component Test cypress/component/
API test, cy.request API Test via Cypress cypress/e2e/api/

Coding Standards (Parts emphasized by the Skill)

Command Chains (CRITICAL): Cypress uses chained APIs, not async/await; do not assign cy.get() to variables for deferred use.

Selector Priority (High to Low): [data-cy] → [data-testid] → cy.contains text → #id → class (marked as fragile).

Anti-pattern Comparison (Excerpt): cy.wait(5000) should be replaced by cy.intercept() + cy.wait('@alias'); avoid testing real third-party sites, use stubs/mocks instead; avoid cramming all logic into a single bloated beforeEach, prefer multiple specs for better isolation.

Validation Workflow:

  1. No arbitrary numerical waits (zero cy.wait(number), use intercept).
  2. Prefer data-cy selectors.
  3. Pure Cypress chaining, no async/await.
  4. Use .should() chains for assertions, not manual judgment.
  5. Test case isolation; use cy.session() for authentication when applicable.

Reference Documents & Advanced Playbook

The Skill points to reference files within the repository, for example:

File Purpose
reference/cloud-integration.md LambdaTest Cypress CLI, parallelism, configuration
reference/component-testing.md React/Vue/Angular component testing
reference/custom-commands.md Custom commands, TypeScript
reference/debugging-flaky.md Flaky tests, DOM, race conditions
reference/playbook.md 15 topics including multi-environment config, cy.session, Page Object, network interception, component testing, DB seed, clock, iframe/Shadow DOM, accessibility, visual regression, CI/CD, etc.

Installation & Enablement

The official release form is a subdirectory in a GitHub repository; no separate npm package name is listed in the retrieved materials. To obtain it:

  1. Open https://github.com/LambdaTest/agent-skills/tree/main/cypress-skill
  2. Add the cypress-skill directory (including SKILL.md and reference/) to the skill path according to your Agent product’s Skills loading instructions.

Metadata snippet (Name and trigger scenarios):

name: cypress-skill
description: >
  Generates production-grade Cypress E2E and component tests in JavaScript
  or TypeScript. Supports local execution and TestMu AI cloud.
languages:
  - JavaScript
  - TypeScript
category: e2e-testing
license: MIT
metadata:
  author: TestMu AI
  version: "1.0"

The installation fields for each IDE/CLI (e.g., Cursor Rules, .claude/skills) depend on the corresponding product documentation; no single-line installation command specific to cypress-skill was provided in the materials, so none is fabricated here.

Typical Usage

Basic E2E Structure

The describe / beforeEach / it pattern recommended by the Skill is as follows (using data-cy for selectors in the example):

describe('Login', () => {
  beforeEach(() => {
    cy.visit('/login');
  });

  it('should login with valid credentials', () => {
    cy.get('[data-cy="username"]').type('user@test.com');
    cy.get('[data-cy="password"]').type('password123');
    cy.get('[data-cy="submit"]').click();
    cy.url().should('include', '/dashboard');
    cy.get('[data-cy="welcome"]').should('contain', 'Welcome');
  });

  it('should show error for invalid credentials', () => {
    cy.get('[data-cy="username"]').type('wrong@test.com');
    cy.get('[data-cy="password"]').type('wrong');
    cy.get('[data-cy="submit"]').click();
    cy.get('[data-cy="error"]').should('be.visible');
  });
});

Network Interception

Stub login API and assert request body, or wait for real API:

cy.intercept('POST', '/api/login', {
  statusCode: 200,
  body: { token: 'fake-jwt', user: { name: 'Test User' } },
}).as('loginRequest');

cy.get('[data-cy="submit"]').click();
cy.wait('@loginRequest').its('request.body').should('deep.include', {
  email: 'user@test.com',
});

cy.intercept('GET', '/api/dashboard').as('dashboardLoad');
cy.visit('/dashboard');
cy.wait('@dashboardLoad');

Custom Commands & cy.session

Encapsulate login in cypress/support/commands.js to reduce repetitive UI steps:

Cypress.Commands.add('login', (email, password) => {
  cy.session([email, password], () => {
    cy.visit('/login');
    cy.get('[data-cy="username"]').type(email);
    cy.get('[data-cy="password"]').type(password);
    cy.get('[data-cy="submit"]').click();
    cy.url().should('include', '/dashboard');
  });
});

// Usage in tests
cy.login('user@test.com', 'password123');

Common Local Commands (Quick Reference)

Task Command
Interactive Open npx cypress open
Headless Run npx cypress run
Specify Spec npx cypress run --spec "cypress/e2e/login.cy.js"
Specify Browser npx cypress run --browser chrome
Component Testing npx cypress run --component
Env Variables CYPRESS_BASE_URL=http://localhost:3000 npx cypress run

TestMu AI / LambdaTest Cloud Execution

Integrate the LambdaTest plugin via setupNodeEvents in cypress.config.js; there is also a lambdatest-config.json example for the cloud side (account credentials come from environment variables LT_USERNAME, LT_ACCESS_KEY, browser matrix and run_settings such as parallels, specs, etc.). Run command:

npx lambdatest-cypress run

Cloud configuration example structure (field names follow official reference):

{
  "lambdatest_auth": {
    "username": "${LT_USERNAME}",
    "access_key": "${LT_ACCESS_KEY}"
  },
  "browsers": [
    { "browser": "Chrome", "platform": "Windows 11", "versions": ["latest"] },
    { "browser": "Firefox", "platform": "macOS Sequoia", "versions": ["latest"] }
  ],
  "run_settings": {
    "build_name": "Cypress Build",
    "parallels": 5,
    "specs": "cypress/e2e/**/*.cy.js"
  }
}

Suitable Scenarios & Notes

Suitable for: Teams that have selected or are evaluating Cypress for Web E2E / component testing; those who want to get test case skeletons conforming to chained API, intercept, and stable selector conventions in a single Agent conversation; those who need to switch between local debugging and TestMu AI cloud/cross-browser execution under the same set of Skill logic.

Notes:

  • The Skill constrains generation and review habits but cannot replace your project’s real cypress.config, dependency versions, and CI secret configurations.
  • The cloud path relies on LambdaTest/TestMu’s Cypress CLI and account; local defaults do not automatically upload to the cloud.
  • Advanced topics (Playwright competitors, non-Cypress stacks) are not within the scope of this Skill; there are other testing framework Skills in the same repository that need to be selected separately.

Conclusion

cypress-skill writes Cypress execution routing, directory conventions, anti-pattern tables, validation checklists, and cloud integration key points into an Agent-readable Skill, reducing “runs but unstable” generated code. If you are building a testing Agent Skill system, you can fix the E2E specifications using this Cypress main line, and then connect references and cloud configurations as needed.

Official URL: https://github.com/LambdaTest/agent-skills/tree/main/cypress-skill

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye