cypress
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to use this skill
何时使用本技能
Use this skill whenever the user wants to:
- Set up Cypress for end-to-end testing
- Write Cypress test cases
- Configure Cypress for component testing
- Integrate Cypress with CI/CD pipelines
- Use Cypress commands and assertions
- Debug Cypress tests
- Optimize Cypress test performance
- Migrate from other testing frameworks to Cypress
- Use Cypress with different frameworks (React, Vue, Angular, Svelte)
- Configure Cypress for different environments
当用户有以下需求时,可使用本技能:
- 为端到端测试搭建Cypress环境
- 编写Cypress测试用例
- 配置Cypress以进行组件测试
- 将Cypress与CI/CD流水线集成
- 使用Cypress命令与断言
- 调试Cypress测试
- 优化Cypress测试性能
- 从其他测试框架迁移至Cypress
- 在不同框架(React、Vue、Angular、Svelte)中使用Cypress
- 为不同环境配置Cypress
How to use this skill
如何使用本技能
This skill is organized to match the Cypress official documentation structure (https://docs.cypress.io/app/get-started/why-cypress, https://docs.cypress.io/api/table-of-contents). When working with Cypress:
-
Identify the topic from the user's request:
- Getting Started/快速开始 →
examples/get-started/ - Core Concepts/核心概念 →
examples/core-concepts/ - Component Testing/组件测试 →
examples/component-testing/ - End-to-End Testing/E2E测试 →
examples/end-to-end-testing/ - Continuous Integration/持续集成 →
examples/continuous-integration/ - Guides/指南 →
examples/guides/ - References/参考 →
examples/references/ - API Reference/API 参考 →
api/
- Getting Started/快速开始 →
-
Load the appropriate example file from thedirectory:
examples/Getting Started (快速开始) -:examples/get-started/examples/get-started/install-cypress.mdexamples/get-started/open-the-app.mdexamples/get-started/why-cypress.md
Core Concepts (核心概念) -:examples/core-concepts/examples/core-concepts/best-practices.mdexamples/core-concepts/interacting-with-elements.mdexamples/core-concepts/introduction-to-cypress.mdexamples/core-concepts/open-mode.mdexamples/core-concepts/retry-ability.mdexamples/core-concepts/test-isolation.mdexamples/core-concepts/testing-types.mdexamples/core-concepts/variables-and-aliases.mdexamples/core-concepts/writing-and-organizing-tests.md
Component Testing (组件测试) -:examples/component-testing/examples/component-testing/angular/api.mdexamples/component-testing/angular/examples.mdexamples/component-testing/angular/overview.mdexamples/component-testing/component-framework-configuration.mdexamples/component-testing/custom-frameworks.mdexamples/component-testing/get-started.mdexamples/component-testing/react/api.mdexamples/component-testing/react/examples.mdexamples/component-testing/react/overview.mdexamples/component-testing/styling-components.mdexamples/component-testing/svelte/api.mdexamples/component-testing/svelte/examples.mdexamples/component-testing/svelte/overview.mdexamples/component-testing/vue/api.mdexamples/component-testing/vue/examples.mdexamples/component-testing/vue/overview.md
End-to-End Testing (E2E测试) -:examples/end-to-end-testing/examples/end-to-end-testing/testing-your-app.mdexamples/end-to-end-testing/writing-your-first-end-to-end-test.md
Continuous Integration (持续集成) -:examples/continuous-integration/examples/continuous-integration/aws-codebuild.mdexamples/continuous-integration/bitbucket-pipelines.mdexamples/continuous-integration/circleci.mdexamples/continuous-integration/github-actions.mdexamples/continuous-integration/gitlab-ci.mdexamples/continuous-integration/overview.md
Guides (指南) -:examples/guides/examples/guides/accessibility-testing.mdexamples/guides/authentication-testing/amazon-cognito-authentication.mdexamples/guides/authentication-testing/auth0-authentication.mdexamples/guides/authentication-testing/azure-active-directory-authentication.mdexamples/guides/authentication-testing/google-authentication.mdexamples/guides/authentication-testing/okta-authentication.mdexamples/guides/authentication-testing/social-authentication.mdexamples/guides/conditional-testing.mdexamples/guides/cross-browser-testing.mdexamples/guides/cross-origin-testing.mdexamples/guides/cypress-studio.mdexamples/guides/debugging.mdexamples/guides/migration/protractor-to-cypress.mdexamples/guides/migration/selenium-to-cypress.mdexamples/guides/network-requests.mdexamples/guides/screenshots-and-videos.mdexamples/guides/stubs-spies-and-clocks.mdexamples/guides/test-retries.md
References (参考) -:examples/references/examples/references/advanced-installation.mdexamples/references/assertions.mdexamples/references/bundled-libraries.mdexamples/references/changelog.mdexamples/references/client-certificates.mdexamples/references/command-line.mdexamples/references/configuration.mdexamples/references/content-security-policy.mdexamples/references/environment-variables.mdexamples/references/error-messages.mdexamples/references/experiments.mdexamples/references/launching-browsers.mdexamples/references/migration-guide.mdexamples/references/module-api.mdexamples/references/proxy-configuration.mdexamples/references/recipes.mdexamples/references/roadmap.mdexamples/references/trade-offs.mdexamples/references/troubleshooting.md
Other Sections:examples/faq.mdexamples/plugins/plugins-guide.mdexamples/plugins/plugins-list.mdexamples/tooling/IDE-integration.mdexamples/tooling/code-coverage.mdexamples/tooling/reporters.mdexamples/tooling/typescript-support.mdexamples/tooling/visual-testing.md
-
Reference API documentation in thedirectory when needed:
api/Commands API -:api/commands/api/commands/and.mdapi/commands/as.mdapi/commands/blur.mdapi/commands/check.mdapi/commands/children.mdapi/commands/clear.mdapi/commands/clearallcookies.mdapi/commands/clearalllocalstorage.mdapi/commands/clearallsessionstorage.mdapi/commands/clearcookie.mdapi/commands/clearcookies.mdapi/commands/clearlocalstorage.mdapi/commands/click.mdapi/commands/clock.mdapi/commands/closest.mdapi/commands/contains.mdapi/commands/dblclick.mdapi/commands/debug.mdapi/commands/document.mdapi/commands/each.mdapi/commands/end.mdapi/commands/eq.mdapi/commands/exec.mdapi/commands/filter.mdapi/commands/find.mdapi/commands/first.mdapi/commands/fixture.mdapi/commands/focus.mdapi/commands/focused.mdapi/commands/get.mdapi/commands/getallcookies.mdapi/commands/getalllocalstorage.mdapi/commands/getallsessionstorage.mdapi/commands/getcookie.mdapi/commands/getcookies.mdapi/commands/go.mdapi/commands/hash.mdapi/commands/hover.mdapi/commands/intercept.mdapi/commands/invoke.mdapi/commands/its.mdapi/commands/last.mdapi/commands/location.mdapi/commands/log.mdapi/commands/mount.mdapi/commands/next.mdapi/commands/nextall.mdapi/commands/nextuntil.mdapi/commands/not.mdapi/commands/origin.md- ... and 43 more command files
Cypress API -:api/cypress-api/api/cypress-api/arch.mdapi/cypress-api/browser.mdapi/cypress-api/catalog-of-events.mdapi/cypress-api/config.mdapi/cypress-api/cookies.mdapi/cypress-api/currentretry.mdapi/cypress-api/currenttest.mdapi/cypress-api/custom-commands.mdapi/cypress-api/custom-queries.mdapi/cypress-api/cypress-log.mdapi/cypress-api/dom.mdapi/cypress-api/element-selector-api.mdapi/cypress-api/ensure.mdapi/cypress-api/env.mdapi/cypress-api/isbrowser.mdapi/cypress-api/iscy.mdapi/cypress-api/keyboard-api.mdapi/cypress-api/platform.mdapi/cypress-api/require.mdapi/cypress-api/screenshot-api.mdapi/cypress-api/session.mdapi/cypress-api/spec.mdapi/cypress-api/stop.mdapi/cypress-api/testing-type.mdapi/cypress-api/version.md
Node Events API -:api/node-events/api/node-events/after-run-api.mdapi/node-events/after-screenshot-api.mdapi/node-events/after-spec-api.mdapi/node-events/before-run-api.mdapi/node-events/before-spec-api.mdapi/node-events/browser-launch-api.mdapi/node-events/configuration-api.mdapi/node-events/overview.mdapi/node-events/preprocessors-api.md
Utilities API -:api/utilities/api/utilities/$.mdapi/utilities/_.mdapi/utilities/blob.mdapi/utilities/buffer.mdapi/utilities/minimatch.mdapi/utilities/promise.mdapi/utilities/sinon.md
Table of Contents -:api/table-of-contents/ -
Follow the specific instructions in that example file for syntax, structure, and best practicesImportant Notes:
- All examples follow Cypress best practices
- Examples include both JavaScript and TypeScript versions where applicable
- Each example file includes parameters, returns, common errors, best practices, and scenarios
- Always check the example file for best practices and common patterns
-
Reference the official documentation when needed:
- Getting Started: https://docs.cypress.io/app/get-started/why-cypress
- API Reference: https://docs.cypress.io/api/table-of-contents
本技能的组织结构与Cypress官方文档结构一致(https://docs.cypress.io/app/get-started/why-cypress, https://docs.cypress.io/api/table-of-contents)。使用Cypress时:
-
从用户需求中确定主题:
- 快速开始 →
examples/get-started/ - 核心概念 →
examples/core-concepts/ - 组件测试 →
examples/component-testing/ - 端到端测试(E2E测试) →
examples/end-to-end-testing/ - 持续集成 →
examples/continuous-integration/ - 指南 →
examples/guides/ - 参考 →
examples/references/ - API参考 →
api/
- 快速开始 →
-
从目录中加载对应的示例文件:
examples/快速开始 -:examples/get-started/examples/get-started/install-cypress.mdexamples/get-started/open-the-app.mdexamples/get-started/why-cypress.md
核心概念 -:examples/core-concepts/examples/core-concepts/best-practices.mdexamples/core-concepts/interacting-with-elements.mdexamples/core-concepts/introduction-to-cypress.mdexamples/core-concepts/open-mode.mdexamples/core-concepts/retry-ability.mdexamples/core-concepts/test-isolation.mdexamples/core-concepts/testing-types.mdexamples/core-concepts/variables-and-aliases.mdexamples/core-concepts/writing-and-organizing-tests.md
组件测试 -:examples/component-testing/examples/component-testing/angular/api.mdexamples/component-testing/angular/examples.mdexamples/component-testing/angular/overview.mdexamples/component-testing/component-framework-configuration.mdexamples/component-testing/custom-frameworks.mdexamples/component-testing/get-started.mdexamples/component-testing/react/api.mdexamples/component-testing/react/examples.mdexamples/component-testing/react/overview.mdexamples/component-testing/styling-components.mdexamples/component-testing/svelte/api.mdexamples/component-testing/svelte/examples.mdexamples/component-testing/svelte/overview.mdexamples/component-testing/vue/api.mdexamples/component-testing/vue/examples.mdexamples/component-testing/vue/overview.md
端到端测试(E2E测试) -:examples/end-to-end-testing/examples/end-to-end-testing/testing-your-app.mdexamples/end-to-end-testing/writing-your-first-end-to-end-test.md
持续集成 -:examples/continuous-integration/examples/continuous-integration/aws-codebuild.mdexamples/continuous-integration/bitbucket-pipelines.mdexamples/continuous-integration/circleci.mdexamples/continuous-integration/github-actions.mdexamples/continuous-integration/gitlab-ci.mdexamples/continuous-integration/overview.md
指南 -:examples/guides/examples/guides/accessibility-testing.mdexamples/guides/authentication-testing/amazon-cognito-authentication.mdexamples/guides/authentication-testing/auth0-authentication.mdexamples/guides/authentication-testing/azure-active-directory-authentication.mdexamples/guides/authentication-testing/google-authentication.mdexamples/guides/authentication-testing/okta-authentication.mdexamples/guides/authentication-testing/social-authentication.mdexamples/guides/conditional-testing.mdexamples/guides/cross-browser-testing.mdexamples/guides/cross-origin-testing.mdexamples/guides/cypress-studio.mdexamples/guides/debugging.mdexamples/guides/migration/protractor-to-cypress.mdexamples/guides/migration/selenium-to-cypress.mdexamples/guides/network-requests.mdexamples/guides/screenshots-and-videos.mdexamples/guides/stubs-spies-and-clocks.mdexamples/guides/test-retries.md
参考 -:examples/references/examples/references/advanced-installation.mdexamples/references/assertions.mdexamples/references/bundled-libraries.mdexamples/references/changelog.mdexamples/references/client-certificates.mdexamples/references/command-line.mdexamples/references/configuration.mdexamples/references/content-security-policy.mdexamples/references/environment-variables.mdexamples/references/error-messages.mdexamples/references/experiments.mdexamples/references/launching-browsers.mdexamples/references/migration-guide.mdexamples/references/module-api.mdexamples/references/proxy-configuration.mdexamples/references/recipes.mdexamples/references/roadmap.mdexamples/references/trade-offs.mdexamples/references/troubleshooting.md
其他章节:examples/faq.mdexamples/plugins/plugins-guide.mdexamples/plugins/plugins-list.mdexamples/tooling/IDE-integration.mdexamples/tooling/code-coverage.mdexamples/tooling/reporters.mdexamples/tooling/typescript-support.mdexamples/tooling/visual-testing.md
-
必要时参考目录中的API文档:
api/命令API -:api/commands/api/commands/and.mdapi/commands/as.mdapi/commands/blur.mdapi/commands/check.mdapi/commands/children.mdapi/commands/clear.mdapi/commands/clearallcookies.mdapi/commands/clearalllocalstorage.mdapi/commands/clearallsessionstorage.mdapi/commands/clearcookie.mdapi/commands/clearcookies.mdapi/commands/clearlocalstorage.mdapi/commands/click.mdapi/commands/clock.mdapi/commands/closest.mdapi/commands/contains.mdapi/commands/dblclick.mdapi/commands/debug.mdapi/commands/document.mdapi/commands/each.mdapi/commands/end.mdapi/commands/eq.mdapi/commands/exec.mdapi/commands/filter.mdapi/commands/find.mdapi/commands/first.mdapi/commands/fixture.mdapi/commands/focus.mdapi/commands/focused.mdapi/commands/get.mdapi/commands/getallcookies.mdapi/commands/getalllocalstorage.mdapi/commands/getallsessionstorage.mdapi/commands/getcookie.mdapi/commands/getcookies.mdapi/commands/go.mdapi/commands/hash.mdapi/commands/hover.mdapi/commands/intercept.mdapi/commands/invoke.mdapi/commands/its.mdapi/commands/last.mdapi/commands/location.mdapi/commands/log.mdapi/commands/mount.mdapi/commands/next.mdapi/commands/nextall.mdapi/commands/nextuntil.mdapi/commands/not.mdapi/commands/origin.md- ... 以及另外43个命令文件
Cypress API -:api/cypress-api/api/cypress-api/arch.mdapi/cypress-api/browser.mdapi/cypress-api/catalog-of-events.mdapi/cypress-api/config.mdapi/cypress-api/cookies.mdapi/cypress-api/currentretry.mdapi/cypress-api/currenttest.mdapi/cypress-api/custom-commands.mdapi/cypress-api/custom-queries.mdapi/cypress-api/cypress-log.mdapi/cypress-api/dom.mdapi/cypress-api/element-selector-api.mdapi/cypress-api/ensure.mdapi/cypress-api/env.mdapi/cypress-api/isbrowser.mdapi/cypress-api/iscy.mdapi/cypress-api/keyboard-api.mdapi/cypress-api/platform.mdapi/cypress-api/require.mdapi/cypress-api/screenshot-api.mdapi/cypress-api/session.mdapi/cypress-api/spec.mdapi/cypress-api/stop.mdapi/cypress-api/testing-type.mdapi/cypress-api/version.md
Node事件API -:api/node-events/api/node-events/after-run-api.mdapi/node-events/after-screenshot-api.mdapi/node-events/after-spec-api.mdapi/node-events/before-run-api.mdapi/node-events/before-spec-api.mdapi/node-events/browser-launch-api.mdapi/node-events/configuration-api.mdapi/node-events/overview.mdapi/node-events/preprocessors-api.md
工具API -:api/utilities/api/utilities/$.mdapi/utilities/_.mdapi/utilities/blob.mdapi/utilities/buffer.mdapi/utilities/minimatch.mdapi/utilities/promise.mdapi/utilities/sinon.md
目录 -:api/table-of-contents/ -
遵循示例文件中的具体指令,包括语法、结构与最佳实践重要说明:
- 所有示例均遵循Cypress最佳实践
- 适用时,示例包含JavaScript与TypeScript两种版本
- 每个示例文件均包含参数、返回值、常见错误、最佳实践与应用场景
- 请务必查看示例文件中的最佳实践与通用模式
-
必要时参考官方文档:
Best Practices
最佳实践
- Use data-cy attributes: Use data-cy attributes for stable, test-friendly selectors
- Avoid hard-coded waits: Leverage Cypress's built-in retry-ability instead of cy.wait()
- Keep tests isolated: Each test should be independent and not rely on other tests
- Use custom commands: Create custom commands for reusable test logic
- Follow assertion patterns: Use Cypress's built-in assertions for better error messages
- Configure properly: Set up cypress.config.js correctly for your project
- Use fixtures: Use fixtures for test data instead of hard-coding values
- Component testing: Use component testing for isolated component testing
- CI/CD integration: Configure Cypress properly for CI/CD environments
- Debug effectively: Use Cypress's debugging tools and commands
- 使用data-cy属性:使用data-cy属性创建稳定、适合测试的选择器
- 避免硬编码等待:利用Cypress内置的重试机制,而非使用cy.wait()
- 保持测试独立性:每个测试应独立运行,不依赖其他测试
- 使用自定义命令:为可复用的测试逻辑创建自定义命令
- 遵循断言模式:使用Cypress内置断言以获得更清晰的错误信息
- 正确配置:为项目正确设置cypress.config.js
- 使用fixtures:使用fixtures存储测试数据,而非硬编码值
- 组件测试:使用组件测试进行独立的组件测试
- CI/CD集成:为CI/CD环境正确配置Cypress
- 高效调试:使用Cypress的调试工具与命令
Resources
资源
- Official Documentation: https://docs.cypress.io/
- Getting Started: https://docs.cypress.io/app/get-started/why-cypress
- API Reference: https://docs.cypress.io/api/table-of-contents
- GitHub Repository: https://github.com/cypress-io/cypress
Keywords
关键词
Cypress, end-to-end testing, E2E testing, component testing, test automation, browser testing, test framework, assertions, commands, fixtures, CI/CD, continuous integration, test runner, 端到端测试, E2E测试, 组件测试, 测试自动化, 浏览器测试, 测试框架, 断言, 命令, 固定数据, 持续集成, 测试运行器
Cypress、端到端测试、E2E测试、组件测试、测试自动化、浏览器测试、测试框架、断言、命令、fixtures、CI/CD、持续集成、测试运行器