ns-e2e-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create E2E Tests

创建E2E测试

Execution-phase Cypress implementation. Planning-phase:
ns-spec-driven/references/e2e-test-task-generator.md
.
执行阶段的Cypress实现。规划阶段参考:
ns-spec-driven/references/e2e-test-task-generator.md

Session boot

会话启动

Load
.nextstage-harness/rules/e2e-tests-rules.mdc
when present. See
references/e2e-architecture.md
for layout and bootstrap summary.
若存在
.nextstage-harness/rules/e2e-tests-rules.mdc
文件,请加载该文件。布局和初始化概要请参考
references/e2e-architecture.md

Phase 0 — Resolve or bootstrap Cypress root

阶段0 — 确定或初始化Cypress根目录

Before any spec or command code, locate the Cypress project or create it.
在编写任何测试用例或命令代码之前,先定位Cypress项目或创建新的Cypress项目。

0.1 — Detect existing E2E (brownfield)

0.1 — 检测已存在的E2E测试(遗留项目)

Search the repo in this order:
  1. tests-e2e/cypress.config.ts
  2. testes-cypress/cypress.config.ts
    (legacy name)
  3. frontend/cypress.config.ts
    (legacy co-located)
Record the directory that contains
cypress.config.ts
as
{e2e_root}
. All paths below are relative to
{e2e_root}
unless noted.
按以下顺序搜索仓库:
  1. tests-e2e/cypress.config.ts
  2. testes-cypress/cypress.config.ts
    (旧命名)
  3. frontend/cypress.config.ts
    (旧的同目录存放方式)
将包含
cypress.config.ts
的目录记录为**
{e2e_root}
**。除非特别说明,以下所有路径均相对于
{e2e_root}

0.2 — Bootstrap when nothing exists (greenfield)

0.2 — 无匹配项时进行初始化(新项目)

If no match in 0.1, create
tests-e2e/
as a standalone Node project:
RuleDetail
Location
tests-e2e/
only
package.json
Here — never add Cypress to
frontend/package.json
TreePer
references/e2e-architecture.md
(config + empty
device/
folders + support imports)
cypress.config.ts
baseUrl
from
CYPRESS_BASE_URL
;
specPattern
cypress/e2e/**/*.cy.ts
Scripts
cypress:open
,
cypress:run
in
tests-e2e/package.json
Then set
{e2e_root} = tests-e2e/
.
Forbidden on greenfield: scaffolding under
frontend/cypress/
, copying deps into the frontend lockfile, or assuming Cypress is already installed in the app package.
如果在0.1中未找到匹配项,则创建**
tests-e2e/
作为独立Node项目**:
规则详情
位置仅限
tests-e2e/
package.json
在此文件中配置——切勿将Cypress添加至
frontend/package.json
目录结构遵循
references/e2e-architecture.md
(配置文件 + 空
device/
文件夹 + 支持文件导入)
cypress.config.ts
baseUrl
取自
CYPRESS_BASE_URL
specPattern
设置为
cypress/e2e/**/*.cy.ts
脚本
tests-e2e/package.json
中添加
cypress:open
cypress:run
命令
然后设置
{e2e_root} = tests-e2e/
新项目禁用操作:在
frontend/cypress/
下搭建测试框架、将依赖复制到前端锁文件中、或假设应用包中已安装Cypress。

0.3 — Post-bootstrap documentation

0.3 — 初始化后文档更新

When
docs/context/stack-confirmed.md
or
architecture-rules.md
exists, add or update the E2E row: location
tests-e2e/
, run command
cd tests-e2e && npm run cypress:run
(or project docker equivalent).
Do not proceed to Phase 1 until
{e2e_root}
is confirmed and
cypress.config.ts
is readable.
若存在
docs/context/stack-confirmed.md
architecture-rules.md
文件,请添加或更新E2E相关条目:位置为
tests-e2e/
,运行命令为
cd tests-e2e && npm run cypress:run
(或项目对应的Docker命令)。
在确认
{e2e_root}
存在且
cypress.config.ts
可读取之前,请勿进入阶段1。

Phase 1 — Discovery (before feature code)

阶段1 — 调研(功能代码编写前)

  1. App under test — routes, forms, API usage, existing
    data-testid
    (read
    frontend/
    , not write Cypress there)
  2. Existing commands — read all
    {e2e_root}/cypress/support/commands/
    ; never duplicate
  3. Config
    {e2e_root}/cypress.config.ts
    baseUrl, env vars (
    CYPRESS_BASE_URL
    ,
    CYPRESS_API_URL
    )
  1. 被测应用——路由、表单、API使用情况、已有的
    data-testid
    (仅读取
    frontend/
    内容,请勿在此处编写Cypress代码)
  2. 已有命令——读取所有
    {e2e_root}/cypress/support/commands/
    下的内容;禁止重复创建
  3. 配置——
    {e2e_root}/cypress.config.ts
    中的baseUrl、环境变量(
    CYPRESS_BASE_URL
    CYPRESS_API_URL

Phase 2 — Command architecture first

阶段2 — 优先构建命令架构

{e2e_root}/cypress/support/commands/
  shared/[feature].commands.ts   # business actions — all devices
  pages/[feature].commands.ts    # page structure
  device/mobile|tablet|desktop.commands.ts
BehaviorLocation
Same on all devices
shared/
Device-exclusive
device/
Page DOM structure
pages/
Register new command files in
{e2e_root}/cypress/support/e2e.ts
.
Specs:
describe
/
it
,
cy.visit()
, commands, assertions — no DOM logic in specs.
{e2e_root}/cypress/support/commands/
  shared/[feature].commands.ts   # business actions — all devices
  pages/[feature].commands.ts    # page structure
  device/mobile|tablet|desktop.commands.ts
行为位置
所有设备通用
shared/
设备专属
device/
页面DOM结构
pages/
{e2e_root}/cypress/support/e2e.ts
中注册新的命令文件。
测试用例:使用
describe
/
it
cy.visit()
、自定义命令、断言——测试用例中禁止包含DOM逻辑

Phase 3 — Spec layout

阶段3 — 测试用例布局

{e2e_root}/cypress/e2e/device/
  desktop/[feature]/[feature]-successful-flows.cy.ts
  tablet/...
  mobile/...
Viewports in
beforeEach
:
  • Desktop: 1280×720
  • Tablet: 768×1024
  • Mobile: 375×812
Forbidden: specs directly under
cypress/e2e/
without
device/
prefix.
{e2e_root}/cypress/e2e/device/
  desktop/[feature]/[feature]-successful-flows.cy.ts
  tablet/...
  mobile/...
beforeEach
中设置视口:
  • 桌面端:1280×720
  • 平板端:768×1024
  • 移动端:375×812
禁止操作:测试用例直接放在
cypress/e2e/
下,不添加
device/
前缀。

Phase 4 — Implement

阶段4 — 实现

  • Use
    data-testid
    from frontend task contract — do not invent
  • No fixed
    cy.wait(N)
    — intercepts or assertion timeouts
  • RBAC: menu hidden + direct URL denial
  • Auth: login via UI or support session; tenant-aware fixtures
  • 使用前端任务约定中的
    data-testid
    ——禁止自行创建
  • 禁止使用固定时长的
    cy.wait(N)
    ——改用拦截或断言超时
  • RBAC:菜单隐藏 + 直接URL访问拒绝
  • 认证:通过UI或支持会话登录;支持多租户的测试数据

Phase 5 — Run and report

阶段5 — 运行与报告

From
{e2e_root}
:
npm run cypress:run
(or docker equivalent documented for the product). Report failures with
ns-investigator
if needed.
SDD version execution: when called under
execution-handoff.md
/
run-implementation
, write or refactor specs only — do not run the E2E suite. The human runs E2E at version end.
{e2e_root}
目录下执行:
npm run cypress:run
(或产品文档中记录的Docker等效命令)。若测试失败,可使用
ns-investigator
进行排查。
SDD版本执行说明:当在
execution-handoff.md
/
run-implementation
下执行时,仅编写或重构测试用例——请勿运行E2E测试套件。测试套件将由相关人员在版本结束时运行。

References

参考文档

FileWhen
references/e2e-architecture.md
Root layout, bootstrap tree, rules
../ns-spec-driven/references/e2e-test-task-generator.md
Task contract source
文件使用场景
references/e2e-architecture.md
根目录布局、初始化目录结构、规则
../ns-spec-driven/references/e2e-test-task-generator.md
任务约定来源

Related skills

相关技能

  • ns-spec-driven
    references/e2e-test-task-generator.md
    — planning tasks with testid contract
  • ns-investigator
    — failing E2E debugging
  • ns-gitlab-ci-generator
    — CI
    cd tests-e2e
    and change paths
  • ns-spec-driven
    references/e2e-test-task-generator.md
    —— 带testid约定的任务规划
  • ns-investigator
    —— 失败E2E测试调试
  • ns-gitlab-ci-generator
    —— CI中的
    cd tests-e2e
    命令及路径变更