name: cypress description: 提供Cypress端到端测试的全面指导,包括命令、断言、组件测试、CI/CD集成和最佳实践。当用户询问Cypress、需要编写E2E测试、组件测试或配置Cypress进行测试时使用。 license: 完整条款在LICENSE.txt中
何时使用此技能
当用户想要以下内容时使用此技能:
- 设置Cypress进行端到端测试
- 编写Cypress测试用例
- 配置Cypress进行组件测试
- 将Cypress与CI/CD管道集成
- 使用Cypress命令和断言
- 调试Cypress测试
- 优化Cypress测试性能
- 从其他测试框架迁移到Cypress
- 在不同框架(React、Vue、Angular、Svelte)中使用Cypress
- 为不同环境配置Cypress
如何使用此技能
此技能的组织结构与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
节点事件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版本(如果适用)
- 每个示例文件包括参数、返回值、常见错误、最佳实践和场景
- 始终检查示例文件以获取最佳实践和常见模式
-
需要时参考官方文档:
最佳实践
- 使用data-cy属性:为稳定、测试友好的选择器使用data-cy属性
- 避免硬编码等待:利用Cypress内置的重试能力,而不是cy.wait()
- 保持测试隔离:每个测试应独立,不依赖其他测试
- 使用自定义命令:为可重用测试逻辑创建自定义命令
- 遵循断言模式:使用Cypress内置断言以获得更好的错误消息
- 正确配置:为项目正确设置cypress.config.js
- 使用夹具:使用夹具代替硬编码值作为测试数据
- 组件测试:使用组件测试进行隔离的组件测试
- CI/CD集成:为CI/CD环境正确配置Cypress
- 有效调试:使用Cypress的调试工具和命令
资源
- 官方文档:https://docs.cypress.io/
- 入门:https://docs.cypress.io/app/get-started/why-cypress
- API参考:https://docs.cypress.io/api/table-of-contents
- GitHub仓库:https://github.com/cypress-io/cypress
关键词
Cypress、端到端测试、E2E测试、组件测试、测试自动化、浏览器测试、测试框架、断言、命令、夹具、CI/CD、持续集成、测试运行器