Cypress测试框架Skill cypress

Cypress测试框架是一个用于端到端测试和组件测试的工具,提供命令、断言、CI/CD集成等全面功能。适用于前端开发测试,支持React、Vue、Angular、Svelte等多种框架,包括设置测试、编写测试用例、调试测试和优化性能。关键词:Cypress、端到端测试、E2E测试、组件测试、测试自动化、浏览器测试、CI/CD集成、测试框架、持续集成。

测试 0 次安装 0 次浏览 更新于 3/22/2026

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时:

  1. 从用户请求中识别主题

    • 入门/快速开始 → examples/get-started/
    • 核心概念 → examples/core-concepts/
    • 组件测试 → examples/component-testing/
    • 端到端测试/E2E测试 → examples/end-to-end-testing/
    • 持续集成 → examples/continuous-integration/
    • 指南 → examples/guides/
    • 参考 → examples/references/
    • API参考 → api/
  2. examples/目录加载适当的示例文件

    入门(快速开始) - examples/get-started/

    • examples/get-started/install-cypress.md
    • examples/get-started/open-the-app.md
    • examples/get-started/why-cypress.md

    核心概念 - examples/core-concepts/

    • examples/core-concepts/best-practices.md
    • examples/core-concepts/interacting-with-elements.md
    • examples/core-concepts/introduction-to-cypress.md
    • examples/core-concepts/open-mode.md
    • examples/core-concepts/retry-ability.md
    • examples/core-concepts/test-isolation.md
    • examples/core-concepts/testing-types.md
    • examples/core-concepts/variables-and-aliases.md
    • examples/core-concepts/writing-and-organizing-tests.md

    组件测试 - examples/component-testing/

    • examples/component-testing/angular/api.md
    • examples/component-testing/angular/examples.md
    • examples/component-testing/angular/overview.md
    • examples/component-testing/component-framework-configuration.md
    • examples/component-testing/custom-frameworks.md
    • examples/component-testing/get-started.md
    • examples/component-testing/react/api.md
    • examples/component-testing/react/examples.md
    • examples/component-testing/react/overview.md
    • examples/component-testing/styling-components.md
    • examples/component-testing/svelte/api.md
    • examples/component-testing/svelte/examples.md
    • examples/component-testing/svelte/overview.md
    • examples/component-testing/vue/api.md
    • examples/component-testing/vue/examples.md
    • examples/component-testing/vue/overview.md

    端到端测试(E2E测试) - examples/end-to-end-testing/

    • examples/end-to-end-testing/testing-your-app.md
    • examples/end-to-end-testing/writing-your-first-end-to-end-test.md

    持续集成 - examples/continuous-integration/

    • examples/continuous-integration/aws-codebuild.md
    • examples/continuous-integration/bitbucket-pipelines.md
    • examples/continuous-integration/circleci.md
    • examples/continuous-integration/github-actions.md
    • examples/continuous-integration/gitlab-ci.md
    • examples/continuous-integration/overview.md

    指南 - examples/guides/

    • examples/guides/accessibility-testing.md
    • examples/guides/authentication-testing/amazon-cognito-authentication.md
    • examples/guides/authentication-testing/auth0-authentication.md
    • examples/guides/authentication-testing/azure-active-directory-authentication.md
    • examples/guides/authentication-testing/google-authentication.md
    • examples/guides/authentication-testing/okta-authentication.md
    • examples/guides/authentication-testing/social-authentication.md
    • examples/guides/conditional-testing.md
    • examples/guides/cross-browser-testing.md
    • examples/guides/cross-origin-testing.md
    • examples/guides/cypress-studio.md
    • examples/guides/debugging.md
    • examples/guides/migration/protractor-to-cypress.md
    • examples/guides/migration/selenium-to-cypress.md
    • examples/guides/network-requests.md
    • examples/guides/screenshots-and-videos.md
    • examples/guides/stubs-spies-and-clocks.md
    • examples/guides/test-retries.md

    参考 - examples/references/

    • examples/references/advanced-installation.md
    • examples/references/assertions.md
    • examples/references/bundled-libraries.md
    • examples/references/changelog.md
    • examples/references/client-certificates.md
    • examples/references/command-line.md
    • examples/references/configuration.md
    • examples/references/content-security-policy.md
    • examples/references/environment-variables.md
    • examples/references/error-messages.md
    • examples/references/experiments.md
    • examples/references/launching-browsers.md
    • examples/references/migration-guide.md
    • examples/references/module-api.md
    • examples/references/proxy-configuration.md
    • examples/references/recipes.md
    • examples/references/roadmap.md
    • examples/references/trade-offs.md
    • examples/references/troubleshooting.md

    其他部分

    • examples/faq.md
    • examples/plugins/plugins-guide.md
    • examples/plugins/plugins-list.md
    • examples/tooling/IDE-integration.md
    • examples/tooling/code-coverage.md
    • examples/tooling/reporters.md
    • examples/tooling/typescript-support.md
    • examples/tooling/visual-testing.md
  3. 需要时参考api/目录中的API文档

    命令API - api/commands/

    • api/commands/and.md
    • api/commands/as.md
    • api/commands/blur.md
    • api/commands/check.md
    • api/commands/children.md
    • api/commands/clear.md
    • api/commands/clearallcookies.md
    • api/commands/clearalllocalstorage.md
    • api/commands/clearallsessionstorage.md
    • api/commands/clearcookie.md
    • api/commands/clearcookies.md
    • api/commands/clearlocalstorage.md
    • api/commands/click.md
    • api/commands/clock.md
    • api/commands/closest.md
    • api/commands/contains.md
    • api/commands/dblclick.md
    • api/commands/debug.md
    • api/commands/document.md
    • api/commands/each.md
    • api/commands/end.md
    • api/commands/eq.md
    • api/commands/exec.md
    • api/commands/filter.md
    • api/commands/find.md
    • api/commands/first.md
    • api/commands/fixture.md
    • api/commands/focus.md
    • api/commands/focused.md
    • api/commands/get.md
    • api/commands/getallcookies.md
    • api/commands/getalllocalstorage.md
    • api/commands/getallsessionstorage.md
    • api/commands/getcookie.md
    • api/commands/getcookies.md
    • api/commands/go.md
    • api/commands/hash.md
    • api/commands/hover.md
    • api/commands/intercept.md
    • api/commands/invoke.md
    • api/commands/its.md
    • api/commands/last.md
    • api/commands/location.md
    • api/commands/log.md
    • api/commands/mount.md
    • api/commands/next.md
    • api/commands/nextall.md
    • api/commands/nextuntil.md
    • api/commands/not.md
    • api/commands/origin.md
    • … 以及43个更多命令文件

    Cypress API - api/cypress-api/

    • api/cypress-api/arch.md
    • api/cypress-api/browser.md
    • api/cypress-api/catalog-of-events.md
    • api/cypress-api/config.md
    • api/cypress-api/cookies.md
    • api/cypress-api/currentretry.md
    • api/cypress-api/currenttest.md
    • api/cypress-api/custom-commands.md
    • api/cypress-api/custom-queries.md
    • api/cypress-api/cypress-log.md
    • api/cypress-api/dom.md
    • api/cypress-api/element-selector-api.md
    • api/cypress-api/ensure.md
    • api/cypress-api/env.md
    • api/cypress-api/isbrowser.md
    • api/cypress-api/iscy.md
    • api/cypress-api/keyboard-api.md
    • api/cypress-api/platform.md
    • api/cypress-api/require.md
    • api/cypress-api/screenshot-api.md
    • api/cypress-api/session.md
    • api/cypress-api/spec.md
    • api/cypress-api/stop.md
    • api/cypress-api/testing-type.md
    • api/cypress-api/version.md

    节点事件API - api/node-events/

    • api/node-events/after-run-api.md
    • api/node-events/after-screenshot-api.md
    • api/node-events/after-spec-api.md
    • api/node-events/before-run-api.md
    • api/node-events/before-spec-api.md
    • api/node-events/browser-launch-api.md
    • api/node-events/configuration-api.md
    • api/node-events/overview.md
    • api/node-events/preprocessors-api.md

    实用工具API - api/utilities/

    • api/utilities/$.md
    • api/utilities/_.md
    • api/utilities/blob.md
    • api/utilities/buffer.md
    • api/utilities/minimatch.md
    • api/utilities/promise.md
    • api/utilities/sinon.md

    目录 - api/table-of-contents/

  4. 遵循该示例文件中的具体指令,了解语法、结构和最佳实践

    重要注意事项

    • 所有示例遵循Cypress最佳实践
    • 示例包括JavaScript和TypeScript版本(如果适用)
    • 每个示例文件包括参数、返回值、常见错误、最佳实践和场景
    • 始终检查示例文件以获取最佳实践和常见模式
  5. 需要时参考官方文档

最佳实践

  1. 使用data-cy属性:为稳定、测试友好的选择器使用data-cy属性
  2. 避免硬编码等待:利用Cypress内置的重试能力,而不是cy.wait()
  3. 保持测试隔离:每个测试应独立,不依赖其他测试
  4. 使用自定义命令:为可重用测试逻辑创建自定义命令
  5. 遵循断言模式:使用Cypress内置断言以获得更好的错误消息
  6. 正确配置:为项目正确设置cypress.config.js
  7. 使用夹具:使用夹具代替硬编码值作为测试数据
  8. 组件测试:使用组件测试进行隔离的组件测试
  9. CI/CD集成:为CI/CD环境正确配置Cypress
  10. 有效调试:使用Cypress的调试工具和命令

资源

关键词

Cypress、端到端测试、E2E测试、组件测试、测试自动化、浏览器测试、测试框架、断言、命令、夹具、CI/CD、持续集成、测试运行器