cypress-automation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<objective>
Production-grade Cypress test suites in TypeScript. The failure this prevents: tests written as if Cypress commands ran synchronously (storing `cy.get()` in a variable, `await cy.click()`), and tests that flake because they wait on `cy.wait(3000)` instead of a network alias. This skill covers the mental model (command queue, retry-ability), project structure, custom commands, network control with `cy.intercept`, component testing, cross-origin auth with `cy.origin`, and Cypress Cloud / CI integration.
</objective>
<objective>
使用TypeScript构建生产级Cypress测试套件。本技能可避免的问题:将Cypress命令当作同步代码编写(例如将`cy.get()`的结果存储到变量中、使用`await cy.click()`),以及因使用`cy.wait(3000)`而非网络别名等待导致的不稳定测试。本技能涵盖核心思维模型(命令队列、重试机制)、项目结构、自定义命令、基于`cy.intercept`的网络控制、组件测试、基于`cy.origin`的跨域认证,以及Cypress Cloud/CI集成。
</objective>
Quick Route
快速导航
| You need to... | Go to |
|---|---|
| Write an E2E spec (load, intercept, assert) | Core Principles + |
Add a typed custom command / | Custom Commands + |
| Mount and test a single component | Component Testing + |
Scaffold | Project Structure + |
| Stub, spy, simulate errors, or poll an API | cy.intercept Patterns + |
| Run in CI / parallelize on Cypress Cloud | CI Integration + |
| Handle an SSO / OAuth redirect | Cross-Origin Flows + |
| 你需要... | 查看位置 |
|---|---|
| 编写E2E测试用例(加载、拦截、断言) | 核心原则 + |
添加类型化自定义命令 / | 自定义命令 + |
| 挂载并测试单个组件 | 组件测试 + |
初始化 | 项目结构 + |
| 存根、监听、模拟错误或轮询API | cy.intercept模式 + |
| 在CI中运行 / 在Cypress Cloud中并行执行 | CI集成 + |
| 处理SSO/OAuth重定向 | 跨域流程 + |
Discovery Questions
调研问题
Check first -- if it exists, use it and skip questions already answered there.
.agents/qa-project-context.md- Component testing, E2E, or both? Component testing mounts individual components in isolation; E2E tests the full app through the browser. Most projects need both. Component testing requires a framework-specific mount (React, Vue, Angular, Svelte).
- Cypress Cloud? Cloud provides parallelization, flake detection, analytics, Test Replay, and the AI add-on. If the team uses it, configure and the record key. If not, everything runs locally or in CI without Cloud.
projectId - TypeScript? Strongly recommended and the default here -- Cypress supports it natively. All examples use TypeScript.
- Framework and bundler? React + Vite, Next.js + Webpack, Vue + Vite, Angular -- component-testing config depends on this.
- Cross-origin auth? If login redirects to a separate domain (SSO, OAuth provider), you need . Note it now so the login command is built for it.
cy.origin - Existing suite or fresh start? If migrating, start with the flakiest or most critical tests, not a big-bang rewrite (see ).
test-migration
首先查看——如果该文件存在,使用其中内容并跳过已回答的问题。
.agents/qa-project-context.md- 组件测试、E2E测试,还是两者都需要? 组件测试会单独隔离挂载组件;E2E测试通过浏览器测试完整应用。大多数项目两者都需要。组件测试需要特定框架的挂载方法(React、Vue、Angular、Svelte)。
- 是否使用Cypress Cloud? Cloud提供并行执行、不稳定测试检测、分析、Test Replay以及AI附加功能。如果团队使用它,需配置和记录密钥。如果不使用,所有测试将在本地或CI中运行,无需Cloud。
projectId - 是否使用TypeScript? 强烈推荐,且为本技能的默认选择——Cypress原生支持TypeScript。所有示例均使用TypeScript。
- 使用的框架和打包工具? React + Vite、Next.js + Webpack、Vue + Vite、Angular——组件测试配置取决于此。
- 是否存在跨域认证? 如果登录重定向到其他域名(SSO、OAuth提供商),则需要使用。请提前记录,以便登录命令适配该场景。
cy.origin - 已有测试套件还是从零开始? 如果是迁移,请从最不稳定或最关键的测试开始,不要一次性重写所有测试(详见)。
test-migration
Core Principles
核心原则
1. Commands Are Enqueued, Not Executed Immediately
1. 命令会被加入队列,而非立即执行
The single most important concept. Cypress commands (, , ) do not execute when called -- they are added to a queue and run serially, asynchronously. You cannot use with Cypress commands, and you cannot store the return value in a variable.
cy.getcy.clickcy.typeasync/awaittypescript
// WRONG -- this looks synchronous but is not
const button = cy.get('[data-testid="submit"]'); // button is a Chainable, not an element
button.click(); // works only by accident, via chaining
// CORRECT -- chain commands; use .then() when you need a value
cy.get('[data-testid="submit"]').click();
cy.get('[data-testid="price"]').invoke('text').then((text) => {
const price = parseFloat(text.replace('$', ''));
expect(price).to.be.greaterThan(0);
});这是最重要的概念。Cypress命令(、、)在调用时不会立即执行——它们会被加入队列,然后串行、异步运行。不能对Cypress命令使用,也不能将返回值存储到变量中。
cy.getcy.clickcy.typeasync/awaittypescript
// 错误写法——看似同步,但实际并非如此
const button = cy.get('[data-testid="submit"]'); // button是Chainable对象,而非DOM元素
button.click(); // 仅通过链式调用偶然生效
// 正确写法——链式调用;需要值时使用.then()
cy.get('[data-testid="submit"]').click();
cy.get('[data-testid="price"]').invoke('text').then((text) => {
const price = parseFloat(text.replace('$', ''));
expect(price).to.be.greaterThan(0);
});2. Retry-ability Is Built-In (For Queries, Not Actions)
2. 重试机制内置(仅适用于查询,不适用于操作)
Cypress automatically retries queries (, , ) and assertions until they pass or time out. It does not retry actions (, , ):
cy.getcy.findcy.containscy.clickcy.typecy.select- waits for the indicator to disappear
cy.get('.loading').should('not.exist') - waits for 5 items
cy.get('.item').should('have.length', 5) - executes once -- if the element is not actionable, it fails
cy.click()
Cypress会自动重试查询命令(、、)和断言,直到它们通过或超时。但不会重试操作命令(、、):
cy.getcy.findcy.containscy.clickcy.typecy.select- 会等待加载指示器消失
cy.get('.loading').should('not.exist') - 会等待5个元素加载完成
cy.get('.item').should('have.length', 5) - 仅执行一次——如果元素不可操作,测试会失败
cy.click()
3. Network Control with cy.intercept
3. 使用cy.intercept进行网络控制
cy.interceptcy.wait(ms)cy.interceptcy.wait(ms)4. Isolation: Each Test Starts Clean
4. 隔离性:每个测试从干净状态开始
Every runs in fresh browser state -- Cypress clears cookies, localStorage, and sessionStorage between tests by default. Tests must not depend on other tests' state or order. Use for shared setup, not inter-test dependencies.
it()beforeEach每个都会在全新的浏览器状态下运行——默认情况下,Cypress会在测试之间清除Cookie、localStorage和sessionStorage。测试不能依赖其他测试的状态或执行顺序。使用进行共享设置,不要在测试间建立依赖。
it()beforeEach5. Data Attributes for Test Selectors
5. 使用数据属性作为测试选择器
Use , , or . They survive CSS refactors, class renames, and localization. Configure the preferred attribute in .
data-testiddata-cydata-testcypress.config.ts使用、或。它们能在CSS重构、类名修改和本地化操作中保留下来。可在中配置首选属性。
data-testiddata-cydata-testcypress.config.tsProject Structure & Configuration
项目结构与配置
Standard layout splits , , , and , with at the root configuring both runners. Key config choices: from env (never hardcode for CI), explicit viewport, for CI, and the framework/bundler pair under . Component specs live under .
e2e/component/fixtures/support/cypress.config.tsbaseUrlretries.runMode: 2component.devServercypress/component/**/*.cy.tsxSee for the directory tree, the complete , and the additions.
references/config-and-commands.mdcypress.config.tstsconfig.json标准布局分为、、和,根目录下的配置两个运行器。关键配置选项:从环境变量获取(CI环境中绝不要硬编码)、显式设置视口、CI模式下,以及下的框架/打包工具组合。组件测试用例存放在。
e2e/component/fixtures/support/cypress.config.tsbaseUrlretries.runMode: 2component.devServercypress/component/**/*.cy.tsx详见中的目录结构、完整以及的补充配置。
references/config-and-commands.mdcypress.config.tstsconfig.jsonCustom Commands
自定义命令
Custom commands encapsulate repeated actions behind a clean, typed API. Common commands: (via + API, not UI), a selector shorthand, and assertion helpers like . Declare them in ( with JSDoc ) so they get autocomplete and compile-time checking.
logincy.sessiongetByTestIdshouldShowToastcypress/support/index.d.tsdeclare namespace Cypress { interface Chainable { ... } }@examplecy.sessionvalidate()cy.sessionvalidate()validate()cy.request('/api/me').its('status').should('eq', 200)Retryable lookups use , and the callback must be a non-arrow -- Cypress binds to apply the command timeout, so an arrow function silently breaks retry-ability. (Intercept handlers are the opposite: is fine there because they do not use .)
Cypress.Commands.addQuery()function () {}this(req) => {}thisSee for the full command definitions, the callback, the example, and the TypeScript declarations.
references/config-and-commands.mdvalidate()addQuery自定义命令将重复操作封装为简洁的类型化API。常见命令:(通过 + API实现,而非UI操作)、选择器简写,以及等断言辅助函数。在中声明(并添加JSDoc),以便获得自动补全和编译时检查。
logincy.sessiongetByTestIdshouldShowToastcypress/support/index.d.tsdeclare namespace Cypress { interface Chainable { ... } }@examplecy.sessionvalidate()cy.sessionvalidate()validate()cy.request('/api/me').its('status').should('eq', 200)可重试的查找需使用,且回调必须是非箭头函数——Cypress会绑定以应用命令超时,箭头函数会静默破坏重试机制。(拦截处理器则相反:是可行的,因为它们不使用。)
Cypress.Commands.addQuery()function () {}this(req) => {}this详见中的完整命令定义、回调、示例以及TypeScript声明。
references/config-and-commands.mdvalidate()addQuerycy.intercept Patterns
cy.intercept模式
cy.intercept- Stub a response — return canned data with , then
{ statusCode, body }.cy.wait('@alias') - Spy without stubbing — , then assert on
cy.intercept('POST', '/api/orders').as('createOrder')andinterception.request.body.interception.response?.statusCode - Conditional responses — drive a closure with to simulate polling (202 → 200). The handler arrow function
callCountis correct here.(req) => { ... } - Network errors — ,
{ statusCode: 500 }, or{ forceNetworkError: true }for slow responses.req.reply({ delay }) - Modify real responses — .
req.continue((res) => { ...; res.send(); }) - Fixture-backed — .
{ fixture: 'api-responses/checkout-success.json' }
Register the intercept before the action that triggers the request, or the alias never matches.
See for runnable code for each, plus cross-origin flows.
references/intercept-patterns.mdcy.intercept- 存根响应 —— 使用返回预设数据,然后调用
{ statusCode, body }。cy.wait('@alias') - 监听不存根 —— ,然后断言
cy.intercept('POST', '/api/orders').as('createOrder')和interception.request.body。interception.response?.statusCode - 条件响应 —— 使用驱动闭包模拟轮询(202 → 200)。此处使用箭头函数
callCount作为处理器是正确的。(req) => { ... } - 网络错误 —— 、
{ statusCode: 500 }或{ forceNetworkError: true }模拟慢响应。req.reply({ delay }) - 修改真实响应 —— 。
req.continue((res) => { ...; res.send(); }) - 基于fixture —— 。
{ fixture: 'api-responses/checkout-success.json' }
请在触发请求的操作之前注册拦截,否则别名永远无法匹配。
详见中的可运行代码示例,以及跨域流程说明。
references/intercept-patterns.mdComponent Testing
组件测试
Component testing mounts a single component in a real browser without running the full app -- faster than E2E, more visual feedback than unit tests. Use , pass / for callbacks, and assert with the same / chain you use in E2E. Never use in a component test. For Vue, use .
cy.mount(<Component .../>)cy.stub()cy.spy()cy.containscy.getcy.visitcy.mount(Component, { props: { ... } })See for a full React component-test suite.
references/component-and-fixtures.mdProductCard组件测试在真实浏览器中挂载单个组件,无需运行完整应用——比E2E测试更快,比单元测试提供更多视觉反馈。使用,为回调传入/,并使用与E2E测试相同的/链式调用进行断言。组件测试中绝不要使用。对于Vue,使用。
cy.mount(<Component .../>)cy.stub()cy.spy()cy.containscy.getcy.visitcy.mount(Component, { props: { ... } })详见中的完整React组件测试套件。
references/component-and-fixtures.mdProductCardData-Driven Testing with Fixtures
使用Fixtures的数据驱动测试
Three layers, depending on where the data comes from:
- Static fixtures — for JSON that rarely changes; read it via
cy.fixture('users').as('users')in athis.users.beforeEach(function () { ... }) - Dynamic data via — register Node-side tasks in
cy.taskfor API calls or DB seeding that must run outside the browser (task bodies run in Node, sosetupNodeEventsthere is Node's global fetch, not a Cypress API).fetch - Environment-specific config — merge a per-environment map in
baseUrl, selected bysetupNodeEvents.--env ENVIRONMENT=...
See for the fixture, seeding, and env-config code.
references/component-and-fixtures.mdcy.task分为三层,取决于数据来源:
- 静态fixtures —— 用于极少变化的JSON数据;在
cy.fixture('users').as('users')中通过beforeEach(function () { ... })读取。this.users - 通过获取动态数据 —— 在
cy.task中注册Node端任务,用于执行必须在浏览器外运行的API调用或数据库初始化(任务体在Node中运行,因此此处的setupNodeEvents是Node的全局fetch,而非Cypress API)。fetch - 环境特定配置 —— 在中合并每个环境的
setupNodeEvents映射,通过baseUrl选择。--env ENVIRONMENT=...
详见中的fixture、初始化以及环境配置代码。
references/component-and-fixtures.mdcy.taskCross-Origin Flows
跨域流程
For legitimate redirects to another domain (SSO, OAuth providers, a separate auth host), wrap the commands that run on the other origin in . This replaced the old / escape hatches -- do not disable web security to work around a redirect. This is distinct from third-party payment iframes (Stripe/PayPal), which you stub with and never reach into.
cy.originchromeWebSecurity: falseexperimentalSessionAndOrigincy.interceptSee (Cross-Origin Flows) for the example.
references/intercept-patterns.mdcy.origin对于合法的重定向到其他域名(SSO、OAuth提供商、独立认证主机),将在其他域名上运行的命令包裹在中。这替代了旧的/解决方案——不要为了处理重定向而禁用Web安全。注意这与第三方支付iframe(Stripe/PayPal)不同,后者需使用存根,绝不要直接操作。
cy.originchromeWebSecurity: falseexperimentalSessionAndOrigincy.intercept详见(跨域流程)中的示例。
references/intercept-patterns.mdcy.originCI Integration
CI集成
Action version: pin to (latest 7.2.0, May 2026). v7 runs under Node 24 and is the current major; use only on a Node 20 runner (the legacy branch).
cypress-io/github-action@v7@v6Cypress / Node support: Current is Cypress 15.x, which supports Node 20, 22, and 24 (Node 18 and 23 dropped). Node 20 removal is a future Cypress 16 / action-v7.2 concern tracking the Node 20 EOL (2026-04-30), not something Cypress 15 did.
- With Cypress Cloud: set , run
projectId, and parallelize across a container matrix (npx cypress run --record --key $CYPRESS_RECORD_KEY) for flake detection, Test Replay, and analytics.fail-fast: false - Without Cloud: use with
cypress-io/github-action@v7/build/start, and uploadwait-on+cypress/screenshotsas artifacts on failure.cypress/videos
See for both complete GitHub Actions workflows.
references/ci-recipes.mdCypress AI (paid Cloud add-on, GA 2026) ships Auto Heal (selector self-healing), AI Test Generation, and AI Bug Triage. Now GA and worth knowing: (English-to-test authoring with runtime self-healing) and Cloud MCP (GA May 2026, free on all Cloud plans) — an MCP server that feeds recorded-run errors, stack traces, and Test Replay links to your AI assistant. This overlaps (selector healing), (failure clustering), and (authoring). If the team is already on Cypress Cloud, buying the add-on may be cheaper than building the equivalent -- flag it during framework selection.
cy.prompttest-reliabilityai-bug-triageai-test-generationAction版本: 固定为(最新版本7.2.0,2026年5月)。v7运行在Node 24环境下,是当前主版本;仅在Node 20运行器上使用(旧分支)。
cypress-io/github-action@v7@v6Cypress/Node支持情况: 当前版本为Cypress 15.x,支持Node 20、22和24(已移除Node 18和23)。Node 20的移除是未来Cypress 16/action-v7.2需要关注的问题,跟踪Node 20的EOL(2026-04-30),并非Cypress 15的改动。
- 使用Cypress Cloud: 设置,运行
projectId,并在容器矩阵中并行执行(npx cypress run --record --key $CYPRESS_RECORD_KEY),以实现不稳定测试检测、Test Replay和分析功能。fail-fast: false - 不使用Cloud: 使用,配置
cypress-io/github-action@v7/build/start,并在测试失败时上传wait-on+cypress/screenshots作为产物。cypress/videos
详见中的完整GitHub Actions工作流示例。
references/ci-recipes.mdCypress AI(付费Cloud附加功能,2026年GA) 包含Auto Heal(选择器自修复)、AI测试生成和AI Bug分类。现已GA,值得关注:(自然语言转测试编写,运行时自修复)和Cloud MCP(2026年5月GA,所有Cloud计划免费)——一个MCP服务器,将录制运行的错误、堆栈跟踪和Test Replay链接提供给AI助手。这与(选择器修复)、(失败聚类)和(测试编写)有重叠。如果团队已使用Cypress Cloud,购买该附加功能可能比自行开发更划算——在框架选择阶段需标记此点。
cy.prompttest-reliabilityai-bug-triageai-test-generationAnti-Patterns
反模式
1. cy.wait(milliseconds) for Synchronization
1. 使用cy.wait(毫秒数)进行同步
typescript
// BAD
cy.get('[data-testid="submit"]').click();
cy.wait(3000);
// GOOD -- wait for network
cy.intercept('POST', '/api/submit').as('submit');
cy.get('[data-testid="submit"]').click();
cy.wait('@submit');Only acceptable for throttle/debounce testing. Everything else waits on a network alias or a DOM assertion.
typescript
// 错误写法
cy.get('[data-testid="submit"]').click();
cy.wait(3000);
// 正确写法——等待网络请求
cy.intercept('POST', '/api/submit').as('submit');
cy.get('[data-testid="submit"]').click();
cy.wait('@submit');仅在测试节流/防抖时可接受。其他场景均应等待网络别名或DOM断言。
2. Conditional Testing Based on DOM State
2. 基于DOM状态进行条件测试
Do not check to conditionally act. Control state deterministically -- stub the API that drives the conditional element.
$body.find(selector).length > 0不要通过来判断是否执行操作。应确定性地控制状态——存根驱动条件元素的API。
$body.find(selector).length > 03. CSS Selectors Over Data Attributes
3. 使用CSS选择器而非数据属性
cy.get('.btn.btn-primary > span')cy.getByTestId('submit')cy.contains('button', 'Place Order')cy.get('.btn.btn-primary > span')cy.getByTestId('submit')cy.contains('button', 'Place Order')4. Sharing State Between Tests
4. 在测试间共享状态
Module-level set in one and read in another creates order-dependent, parallel-unsafe tests. Each test sets up its own data via or in .
let orderIdit()cy.requestcy.taskbeforeEach在一个中设置模块级变量并在另一个中读取,会导致测试依赖执行顺序且无法并行运行。每个测试应通过中的或自行设置数据。
it()let orderIdit()beforeEachcy.requestcy.task5. Testing Third-Party Iframes
5. 测试第三方iframe
Do not reach into Stripe/PayPal iframes. Mock the payment API with and assert on your own UI.
cy.intercept不要直接操作Stripe/PayPal的iframe。使用模拟支付API,并断言自身UI。
cy.intercept6. Not Using cy.session() for Login (or Omitting validate())
6. 不使用cy.session()进行登录(或省略validate())
UI login in every test is slow and fragile. Use to authenticate via API once and cache it -- with a callback so an expired token does not silently reuse a dead session.
cy.sessionvalidate()每个测试都通过UI登录既慢又脆弱。使用通过API认证一次并缓存会话——务必添加回调,避免过期令牌静默复用失效会话。
cy.sessionvalidate()7. Arrow Function in addQuery
7. 在addQuery中使用箭头函数
A custom query written with silently loses its retry timeout because Cypress needs . Use .
addQuery('name', (arg) => { ... })thisfunction (arg) { ... }使用编写的自定义查询会静默丢失超时重试机制,因为Cypress需要。请使用。
addQuery('name', (arg) => { ... })thisfunction (arg) { ... }8. Running All Tests Serially in CI
8. 在CI中串行运行所有测试
Parallelize once the suite exceeds 5 minutes -- Cypress Cloud, , or manual sharding across a CI matrix.
cypress-split当测试套件执行时间超过5分钟时,应并行执行——可使用Cypress Cloud、或在CI矩阵中手动分片。
cypress-splitFailure Modes
故障模式
| Symptom | Likely cause | Fix |
|---|---|---|
| A yielded element was reused after a re-render | Re-query inside |
| Wrong method or glob, or intercept registered after the action | Register the intercept before the triggering command; verify method + URL glob |
| Login or flow crosses to another domain | Wrap the other-origin commands in |
| Session reused but user is logged out | | Add a |
| Custom query never times out / retries forever | | Convert to |
| 症状 | 可能原因 | 修复方案 |
|---|---|---|
| 渲染后复用了之前获取的元素 | 在 |
| 请求方法或URL匹配错误,或拦截在操作后注册 | 在触发命令前注册拦截;验证请求方法+URL匹配规则 |
重定向时出现 | 登录或流程跨域 | 将跨域命令包裹在 |
| 会话被复用但用户已登出 | | 添加调用认证接口的 |
| 自定义查询永不超时 / 无限重试 | | 转换为 |
Verification
验证
Prove the suite runs before calling it done:
- — confirms the Cypress binary is installed and runnable.
npx cypress verify - — should exit 0 (headless, in CI mode).
npx cypress run --spec "cypress/e2e/<file>.cy.ts" - — component specs exit 0.
npx cypress run --component --spec "cypress/component/<File>.cy.tsx" - — custom-command declarations in
npx tsc --noEmitcompile against the test files.index.d.ts
完成前需验证套件可正常运行:
- —— 确认Cypress二进制文件已安装且可运行。
npx cypress verify - —— 应返回0(无头模式,CI模式)。
npx cypress run --spec "cypress/e2e/<file>.cy.ts" - —— 组件测试用例应返回0。
npx cypress run --component --spec "cypress/component/<File>.cy.tsx" - ——
npx tsc --noEmit中的自定义命令声明应能与测试文件编译通过。index.d.ts
Done When
完成标准
- exists with a
cypress.config.tsfrom env (not hardcodedbaseUrlin CI) and explicitlocalhost/viewportWidth;viewportHeightpasses.npx cypress verify - Custom commands extracted to with TypeScript declarations in
cypress/support/commands.ts;cypress/support/index.d.tsexits 0.npx tsc --noEmit - The command uses
loginwith acy.sessioncallback.validate() - No for synchronization in the suite (
cy.wait(<number>)returns nothing except documented throttle/debounce cases).grep -rn "cy.wait([0-9]" cypress/ - Component specs live under and run with
cypress/component/**/*.cy.tsxexiting 0.npx cypress run --component - E2E specs pass in CI (exits 0) with either a recorded Cypress Cloud run (parallel) or local video/screenshot artifacts uploaded on failure.
npx cypress run
- 存在,从环境变量获取
cypress.config.ts(CI环境中不硬编码baseUrl),并显式设置localhost/viewportWidth;viewportHeight通过。npx cypress verify - 自定义命令提取到,并在
cypress/support/commands.ts中添加TypeScript声明;cypress/support/index.d.ts返回0。npx tsc --noEmit - 命令使用带
login回调的validate()。cy.session - 套件中无用于同步的(
cy.wait(<数字>)无结果,除非是文档说明的节流/防抖测试场景)。grep -rn "cy.wait([0-9]" cypress/ - 组件测试用例存放在,且
cypress/component/**/*.cy.tsx返回0。npx cypress run --component - E2E测试用例在CI中通过(返回0),要么记录到Cypress Cloud(并行执行),要么在失败时上传本地视频/截图产物。
npx cypress run
Reference Files (in references/
)
references/参考文件(位于references/
)
references/- config-and-commands.md — Project directory tree, full , and custom commands (
cypress.config.ts+cy.session, the non-arrowvalidate()) with TypeScript declarations.addQuery - intercept-patterns.md — Every recipe (stub, spy, conditional/polling, error simulation, response modification, fixture-backed) plus cross-origin flows with
cy.intercept.cy.origin - component-and-fixtures.md — React component-test suite plus data-driven testing (static fixtures, seeding, env-specific config).
cy.task - ci-recipes.md — GitHub Actions workflows with and without Cypress Cloud, on , with parallelization and artifact upload.
@v7
- config-and-commands.md —— 项目目录结构、完整、自定义命令(带
cypress.config.ts的validate()、非箭头函数的cy.session)以及TypeScript声明。addQuery - intercept-patterns.md —— 所有示例(存根、监听、条件/轮询、错误模拟、响应修改、基于fixture),以及基于
cy.intercept的跨域流程。cy.origin - component-and-fixtures.md —— React组件测试套件,以及数据驱动测试(静态fixtures、初始化、环境特定配置)。
cy.task - ci-recipes.md —— 使用和不使用Cypress Cloud的GitHub Actions工作流,基于,包含并行执行和产物上传。
@v7
Related Skills
相关技能
- playwright-automation — Use instead of this skill when the suite is Playwright, not Cypress. Same E2E goals, different runner and API.
- test-reliability — Go here for runtime per-test flake healing, self-healing locators, and quarantine. This skill writes stable tests; that one repairs failing ones.
- selector-drift-recovery — Bulk-regenerate broken selectors after a UI refactor or redesign; this skill is for authoring, not mass repair.
- test-migration — Converting Selenium/other suites to Cypress.
- ci-cd-integration — Pipeline templates for running Cypress in GitHub Actions / GitLab CI, parallelization, and artifact management.
- visual-testing — Visual regression to complement Cypress functional tests; Cypress has no built-in pixel comparison.
- unit-testing — Jest/Vitest for logic that needs no browser; Cypress component tests fill the gap between unit and E2E.
- test-data-management — Seeding, managing, and cleaning up the test data Cypress tests consume.
- qa-project-context — The project context file capturing framework choices, CI platform, and conventions.
- playwright-automation —— 当测试套件为Playwright而非Cypress时,使用该技能。目标相同,但运行器和API不同。
- test-reliability —— 用于运行时单测不稳定修复、自修复定位器和隔离。本技能用于编写稳定测试;该技能用于修复失败测试。
- selector-drift-recovery —— UI重构或重新设计后批量重新生成失效选择器;本技能用于编写测试,而非批量修复。
- test-migration —— 将Selenium/其他套件迁移到Cypress。
- ci-cd-integration —— 在GitHub Actions/GitLab CI中运行Cypress的流水线模板、并行执行和产物管理。
- visual-testing —— 视觉回归测试,补充Cypress功能测试;Cypress无内置像素对比功能。
- unit-testing —— 使用Jest/Vitest测试无需浏览器的逻辑;Cypress组件测试填补了单元测试与E2E测试之间的空白。
- test-data-management —— 初始化、管理和清理Cypress测试使用的测试数据。
- qa-project-context —— 记录框架选择、CI平台和约定的项目上下文文件。