关于 cypress
cypress 是一项借助文档示例和 API 参考指导 Cypress 使用的技能,涵盖端到端与组件测试中的安装、编写、配置、调试和迁移。
主要功能
- 01Cypress 安装与配置
- 02端到端测试编写
- 03组件测试指导
- 04CI/CD 集成指导
- 05调试与性能建议
- 06从其他测试框架迁移
适用场景
- 01为项目配置 Cypress
- 02编写浏览器端到端测试
- 03测试支持框架中的组件
- 04排查失败的测试
- 05从其他框架迁移测试
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ full-stack-skills/ testing-skills --skill cypress安装后在 Claude Code 中输入/cypress确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
agents/openai.yamlapi/commands/and.mdas.mdblur.mdcheck.mdchildren.mdclear.mdclearallcookies.mdclearalllocalstorage.mdclearallsessionstorage.mdclearcookie.mdclearcookies.mdclearlocalstorage.mdclick.mdclock.mdclosest.mdcontains.mddblclick.mddebug.mddocument.mdeach.mdend.mdeq.mdexec.mdfilter.mdfind.mdfirst.mdfixture.mdfocus.mdfocused.md详细介绍
适用场景
在用户希望执行以下操作时,使用此技能:
- 设置 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 时:
-
根据用户的请求确定主题:
- 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/快速开始 →
-
从
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指南 (指南) -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 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
目录 -
api/table-of-contents/: -
遵循该示例文件中的具体说明,以了解语法、结构和最佳实践
重要说明:
- 所有示例均遵循 Cypress 最佳实践
- 适用时,示例会同时提供 JavaScript 和 TypeScript 版本
- 每个示例文件都包含参数、返回值、常见错误、最佳实践和使用场景
- 请务必查看示例文件,了解最佳实践和常见模式
-
必要时参考官方文档:
最佳实践
- 使用 data-cy 属性:使用 data-cy 属性作为稳定且便于测试的选择器
- 避免硬编码等待:利用 Cypress 内置的重试能力,而不是使用 cy.wait()
- 保持测试相互独立:每项测试都应独立运行,不依赖其他测试
- 使用自定义命令:为可复用的测试逻辑创建自定义命令
- 遵循断言模式:使用 Cypress 内置断言,以获得更好的错误消息
- 正确配置:为项目正确设置 cypress.config.js
- 使用 fixtures:使用 fixtures 存放测试数据,而不是硬编码值
- 组件测试:使用组件测试,对独立组件进行测试
- 集成 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 测试、组件测试、测试自动化、浏览器测试、测试框架、断言、命令、fixtures、CI/CD、持续集成、测试运行器、端到端测试、E2E 测试、组件测试、测试自动化、浏览器测试、测试框架、断言、命令、固定数据、持续集成、测试运行器