Previous
Day 28 · Test Data Management and Environment Strategy
Next
Day 30 · Final Project and Next Steps
进阶掌握
Day 2960-120 minutesPlaywright QA hands-on drill

Day 29 - Framework Design and Team Standards

今日目标

  • 从“会写脚本”升级到“能维护框架”。
  • 建立团队级规范。

学习时间安排(60–120 分钟)

时间模块做什么
0-20 分钟核心概念与词汇读概念表,重点理解规范要约束的行为。
20-45 分钟学习材料阅读读最佳实践文档,对照自己项目的目录和规范。
45-75 分钟实操练习写《Playwright 自动化测试规范 v1.0》。
75-105 分钟示例代码改写按规范整改自己项目里的不合规代码。
105-120 分钟复盘与作业完成 PR review checklist,完成今日问题。

核心概念与词汇

English中文场景用法
framework测试框架Use it when you describe the structure, conventions, and utilities around raw tests.
naming convention命名规范Use it when you standardize file, test, and variable names.
locator convention定位器规范Use it when you standardize which locator APIs the team may use.
code review checklist代码审查清单Use it when PRs must pass a fixed set of test-quality checks.
flaky test policy不稳定测试处理流程Use it when the team decides to fix, quarantine, or delete flaky tests.
tag convention标签规范Use it when @smoke/@regression tags drive CI test selection.
CI run strategyCI 运行策略Use it when you document which tests run when.
failure triage flow失败排查流程Use it when failures route to owners with evidence attached.
maintainability可维护性Use it when you judge whether new teammates can change tests safely.
return on investment自动化收益Use it when you measure bugs caught and time saved against maintenance cost.

学习材料

  • 必读:[Best practices](https://playwright.dev/docs/best-practices)
  • 必读:[POM](https://playwright.dev/docs/pom) 和 [Fixtures](https://playwright.dev/docs/test-fixtures)(复习 Day 13/14)
  • 选读:[Test annotations](https://playwright.dev/docs/test-annotations)(tag 规范的基础)

重点理解

推荐项目结构:

e2e/
  tests/
    smoke/
    regression/
    api/
  pages/
  fixtures/
  utils/
  test-data/
  config/
  reports/
  README.md

团队规范:

  • 命名规范。
  • Locator 规范。
  • POM 规范。
  • 测试数据规范。
  • Tag 规范。
  • CI 运行策略。
  • 失败排查流程。
  • Code review checklist。
  • Flaky test 处理流程。

实操步骤

写一份《Playwright 自动化测试规范 v1.0》。

必须包含:

  • 测试用例命名。
  • 文件目录。
  • locator 优先级。
  • 断言规则。
  • 等待规则。
  • 数据管理。
  • CI 策略。
  • review checklist。

示例代码

## Locator 规范(节选)

1. 优先级:getByRole > getByLabel > getByPlaceholder > getByText > getByTestId > CSS/XPath
2. 禁止超过 2 层的 CSS/XPath 选择器
3. 列表操作遵循「先容器、后 filter、再操作」
4. nth 仅允许在顺序是业务规则时使用,并注明理由

## 断言规范(节选)

1. 每条测试至少 1 个业务断言
2. 禁止手动 textContent 比较
3. 断言用户可见结果,不断言 class 名

常见坑

  • 规范写了没人执行,review 也不看,文档成为摆设。
  • 规范过细(规定到变量命名风格),新人遵守成本高,反而被绕过。
  • 只约束怎么写,不约束“失败怎么办”,flaky 堆积无人处理。
  • 框架过度设计:为了抽象而抽象,核心路径还没稳定就上微框架。
  • 用“重构框架”代替“修复 flaky”,框架越来越复杂,测试还是红。

今日产出

  • 一份团队规范文档。
  • 一份 PR review checklist。

今日问题

  1. 自动化测试项目为什么需要规范?
  2. 什么样的测试代码最难维护?
  3. Code review 应该重点看什么?
  4. flaky test 应该删除、跳过还是修复?
  5. 如何衡量自动化测试带来的价值?

复盘要点

  • 规范的目的是减少决策成本,不是展示写作能力:能执行的 5 条胜过纸面的 50 条。
  • review 是规范的执行器:checklist 里没有的项,规范就只是文档。
  • 你维护的不是“测试代码”,而是团队对质量的共同理解。

AI 时代扩展:AI 辅助 Playwright 测试

新增概念

English中文
standards enforcement规范执行
automated code review自动化代码审查
flaky quarantine不稳定用例隔离

适用场景

让 AI 起草团队规范初稿,或按你的规范审查测试代码、给出不合规清单。也可以用 AI 把规范转成 CI 上的 lint 规则建议。

可复用表达 / 提示词

请根据以下要求起草《Playwright 自动化测试规范》:覆盖命名、locator、断言、等待、数据、CI 六个方面,每条规范附一个违规示例。
请按这份规范审查我的测试代码,输出不合规项清单,按严重程度排序。

追问加练

  • AI 起草的规范里,哪些条目无法自动化检查?
  • flaky 用例隔离(quarantine)的流程怎么设计?
  • 规范由 AI 起草后,团队评审重点应该看什么?

今日作业

  • 完成《Playwright 自动化测试规范 v1.0》全部 8 项内容。
  • 完成 PR review checklist,至少 10 条。
  • 用 AI 按规范审查你的项目,整改不合规项。

自检清单

Previous
Day 28 · Test Data Management and Environment Strategy
Next
Day 30 · Final Project and Next Steps