e2e-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

E2E Tests

E2E测试

Act as a top-tier software engineer with serious testing skills.
Write e2e tests for: $ARGUMENTS
Each test must answer these 5 questions:
  1. What is the user flow under test? (test should be in a named describe block)
  2. What is the expected behavior? ($given and $should arguments are adequate)
  3. What actions does the user perform? (navigations, clicks, form fills, etc.)
  4. What is the expected outcome? (visible elements, URLs, toasts, database state)
  5. How can we find the bug? (implicitly answered if the above questions are answered correctly)
请以具备专业测试能力的顶尖软件工程师身份行事。
为以下内容编写E2E测试:$ARGUMENTS
每个测试必须回答以下5个问题:
  1. 被测的用户流程是什么?(测试应放在命名的describe块中)
  2. 预期行为是什么?($given和$should参数已足够说明)
  3. 用户执行哪些操作?(导航、点击、表单填写等)
  4. 预期结果是什么?(可见元素、URL、提示框、数据库状态)
  5. 如何发现bug?(如果上述问题都正确回答,此问题会间接得到解答)

Rules

规则

  • Use Playwright with test, expect, and test.describe.
  • Tests must use the "given: ..., should: ..." prose format.
  • Test files live in
    playwright/
    directory, organized by feature subdirectories.
  • Test files use the
    .e2e.ts
    extension.
  • Prefer accessible locators:
    getByRole
    ,
    getByLabel
    ,
    getByText
    over CSS selectors.
  • Use
    getByRole
    with name option as the primary locator strategy.
  • When accessible locators are insufficient, use
    data-testid
    attributes via
    getByTestId
    .
  • Never use CSS class selectors for test locators — classes are for styling, not testing.
  • Define
    data-testid
    values as named exports in a shared constants file (e.g.
    app/test/test-ids.ts
    ) and import them in both the component and the test.
  • Use regex with case-insensitive flag for text matching:
    { name: /submit/i }
    .
  • Await all Playwright actions and assertions.
  • Use
    toBeVisible()
    and
    toBeHidden()
    for element presence checks.
  • Use
    toHaveURL()
    or a
    getPath(page)
    helper for URL assertions.
  • Handle auth setup in helper functions, not inline in every test.
  • Clean up test data in teardown — don't leave state for the next test.
  • Each test should be independent and not depend on other tests' state.
  • Block images in performance-sensitive tests via
    page.route
    .
  • Use
    test.describe
    blocks to group related scenarios.
  • Assert toast notifications via
    getByRole("region", { name: /notifications/i })
    .
  • For forms, use
    getByRole("textbox", { name: /label/i })
    and
    .fill()
    .
  • For dropdowns, use
    getByRole("combobox")
    then
    getByRole("option")
    .
  • For accessibility checks, use
    @axe-core/playwright
    with
    expect(results.violations).toEqual([])
    .
  • Create reusable setup/teardown helpers for common flows (login, org creation, etc.).
  • Use factories from the codebase to create test data — never hardcode full objects.
  • Verify database state after mutations using model functions from infrastructure layer.
  • 使用Playwright的test、expect和test.describe方法。
  • 测试必须采用"given: ..., should: ..."的叙述格式。
  • 测试文件存放于
    playwright/
    目录下,按功能子目录进行组织。
  • 测试文件使用
    .e2e.ts
    扩展名。
  • 优先使用可访问性定位器:
    getByRole
    getByLabel
    getByText
    ,而非CSS选择器。
  • 优先采用带name选项的
    getByRole
    作为定位策略。
  • 当可访问性定位器无法满足需求时,通过
    getByTestId
    使用
    data-testid
    属性。
  • 切勿使用CSS类选择器作为测试定位器——类是用于样式设计的,而非测试。
  • 在共享常量文件(如
    app/test/test-ids.ts
    )中将
    data-testid
    值定义为命名导出,并在组件和测试中都导入这些值。
  • 文本匹配时使用带不区分大小写标志的正则表达式:
    { name: /submit/i }
  • 等待所有Playwright操作和断言完成。
  • 使用
    toBeVisible()
    toBeHidden()
    检查元素是否存在。
  • 使用
    toHaveURL()
    getPath(page)
    辅助函数进行URL断言。
  • 在辅助函数中处理身份验证设置,不要在每个测试中内联编写。
  • 在测试拆解阶段清理测试数据——不要为下一个测试留下状态。
  • 每个测试都应独立,不依赖其他测试的状态。
  • 在对性能敏感的测试中,通过
    page.route
    阻止图片加载。
  • 使用
    test.describe
    块对相关场景进行分组。
  • 通过
    getByRole("region", { name: /notifications/i })
    断言提示框通知。
  • 对于表单,使用
    getByRole("textbox", { name: /label/i })
    .fill()
    方法。
  • 对于下拉菜单,先使用
    getByRole("combobox")
    ,再使用
    getByRole("option")
  • 对于可访问性检查,使用
    @axe-core/playwright
    并断言
    expect(results.violations).toEqual([])
  • 为常见流程(登录、组织创建等)创建可复用的设置/拆解辅助函数。
  • 使用代码库中的工厂函数创建测试数据——切勿硬编码完整对象。
  • 使用基础设施层的模型函数验证数据变更后的数据库状态。