e2e-tests
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseE2E 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:
- What is the user flow under test? (test should be in a named describe block)
- What is the expected behavior? ($given and $should arguments are adequate)
- What actions does the user perform? (navigations, clicks, form fills, etc.)
- What is the expected outcome? (visible elements, URLs, toasts, database state)
- How can we find the bug? (implicitly answered if the above questions are answered correctly)
请以具备专业测试能力的顶尖软件工程师身份行事。
为以下内容编写E2E测试:$ARGUMENTS
每个测试必须回答以下5个问题:
- 被测的用户流程是什么?(测试应放在命名的describe块中)
- 预期行为是什么?($given和$should参数已足够说明)
- 用户执行哪些操作?(导航、点击、表单填写等)
- 预期结果是什么?(可见元素、URL、提示框、数据库状态)
- 如何发现bug?(如果上述问题都正确回答,此问题会间接得到解答)
Rules
规则
- Use Playwright with test, expect, and test.describe.
- Tests must use the "given: ..., should: ..." prose format.
- Test files live in directory, organized by feature subdirectories.
playwright/ - Test files use the extension.
.e2e.ts - Prefer accessible locators: ,
getByRole,getByLabelover CSS selectors.getByText - Use with name option as the primary locator strategy.
getByRole - When accessible locators are insufficient, use attributes via
data-testid.getByTestId - Never use CSS class selectors for test locators — classes are for styling, not testing.
- Define values as named exports in a shared constants file (e.g.
data-testid) and import them in both the component and the test.app/test/test-ids.ts - Use regex with case-insensitive flag for text matching: .
{ name: /submit/i } - Await all Playwright actions and assertions.
- Use and
toBeVisible()for element presence checks.toBeHidden() - Use or a
toHaveURL()helper for URL assertions.getPath(page) - 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 blocks to group related scenarios.
test.describe - Assert toast notifications via .
getByRole("region", { name: /notifications/i }) - For forms, use and
getByRole("textbox", { name: /label/i })..fill() - For dropdowns, use then
getByRole("combobox").getByRole("option") - For accessibility checks, use with
@axe-core/playwright.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,而非CSS选择器。getByText - 优先采用带name选项的作为定位策略。
getByRole - 当可访问性定位器无法满足需求时,通过使用
getByTestId属性。data-testid - 切勿使用CSS类选择器作为测试定位器——类是用于样式设计的,而非测试。
- 在共享常量文件(如)中将
app/test/test-ids.ts值定义为命名导出,并在组件和测试中都导入这些值。data-testid - 文本匹配时使用带不区分大小写标志的正则表达式:。
{ name: /submit/i } - 等待所有Playwright操作和断言完成。
- 使用和
toBeVisible()检查元素是否存在。toBeHidden() - 使用或
toHaveURL()辅助函数进行URL断言。getPath(page) - 在辅助函数中处理身份验证设置,不要在每个测试中内联编写。
- 在测试拆解阶段清理测试数据——不要为下一个测试留下状态。
- 每个测试都应独立,不依赖其他测试的状态。
- 在对性能敏感的测试中,通过阻止图片加载。
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([]) - 为常见流程(登录、组织创建等)创建可复用的设置/拆解辅助函数。
- 使用代码库中的工厂函数创建测试数据——切勿硬编码完整对象。
- 使用基础设施层的模型函数验证数据变更后的数据库状态。