2026-10-16 15:38:20 +08:00
<!DOCTYPE html>
< html lang = "zh-CN" data-theme = "light" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > UI 自动化: Playwright 与 Selenium · 阶段 2 · 自动化 模块 4 · 测试开发工程师从零到成熟< / title >
< meta name = "description" content = "UI 自动化: Playwright 与 Selenium 模块目录:共 13 章、60 个小节。" >
< link rel = "stylesheet" href = "../../assets/doc.css" >
< / head >
< body >
< header class = "topbar" >
< div class = "tb-in" >
< a class = "brand" href = "../../index.html" > < span class = "logo" > QA< / span > < div > 从零到成熟< small > 测试开发 · 模块详解< / small > < / div > < / a >
< div class = "crumbs" >
< a href = "../../index.html" > 学习路径< / a > < span class = "sep" > /< / span >
< a href = "../../index.html#s2" > 阶段 2 · 自动化< / a > < span class = "sep" > /< / span >
< b > UI 自动化: Playwright 与 Selenium< / b >
< / div >
< div class = "spacer" > < / div >
< button class = "btn" id = "tocToggle" > ☰ 导航< / button >
< button class = "btn" id = "themeBtn" title = "切换到深色主题" > 深色< / button >
< / div >
< / header >
< div class = "layout" id = "layout" >
< aside class = "sidebar" >
< h2 > 章节目录< / h2 >
< nav id = "chapters" > < a class = "toc-a" href = "01-why.html" > < i class = "cn" > 1< / i > UI 自动化到底该覆盖什么< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "01-why.html#sec-1-1" > 一次「UI 自动化全覆盖」的失败尝试< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-2" > 成本结构:写一次,养十次< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-3" > 只覆盖冒烟与核心链路的取舍依据< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-4" > 这一模块的交付物与验收标准< / a > < a class = "toc-a lv3" href = "01-why.html#sec-1-5" > 学习路线与练法< / a > < / div > < a class = "toc-a" href = "02-locate.html" > < i class = "cn" > 2< / i > 元素定位:选择器为什么必须和开发一起定< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "02-locate.html#sec-2-1" > 定位方式的优先级: testid、语义、CSS、XPath、文本< / a > < a class = "toc-a lv3" href = "02-locate.html#sec-2-2" > 为什么 XPath 与文本定位最先烂掉< / a > < a class = "toc-a lv3" href = "02-locate.html#sec-2-3" > data-testid 约定:怎么和开发谈< / a > < a class = "toc-a lv3" href = "02-locate.html#sec-2-4" > 定位到多个元素:严格模式与调试< / a > < a class = "toc-a lv3" href = "02-locate.html#sec-2-5" > 定位自查:改一次文案就红说明什么< / a > < / div > < a class = "toc-a" href = "03-wait.html" > < i class = "cn" > 3< / i > 等待机制: sleep 为什么一定会出事< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "03-wait.html#sec-3-1" > 三种等待:隐式、显式与自动等待< / a > < a class = "toc-a lv3" href = "03-wait.html#sec-3-2" > Playwright 的自动等待替你挡掉了什么< / a > < a class = "toc-a lv3" href = "03-wait.html#sec-3-3" > 显式等待的正确写法:等状态,不等时间< / a > < a class = "toc-a lv3" href = "03-wait.html#sec-3-4" > 网络等待与页面就绪的判据< / a > < a class = "toc-a lv3" href = "03-wait.html#sec-3-5" > 从 flaky 到稳定:等待问题的定位方法< / a > < / div > < a class = "toc-a" href = "04-po.html" > < i class = "cn" > 4< / i > 页面对象模式:把选择器关进一个地方< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "04-po.html#sec-4-1" > 没有页面对象的用例长什么样< / a > < a class = "toc-a lv3" href = "04-po.html#sec-4-2" > 一个页面的页面对象怎么写< / a > < a class = "toc-a lv3" href = "04-po.html#sec-4-3" > 组件对象:弹窗、表格与分页< / a > < a class = "toc-a lv3" href = "04-po.html#sec-4-4" > 断言放哪里:页面对象只封装操作< / a > < a class = "toc-a lv3" href = "04-po.html#sec-4-5" > 页面对象的过度设计:什么时候不需要它< / a > < / div > < a class = "toc-a" href = "05-select.html" > < i class = "cn" > 5< / i > 框架选型: Playwright、Selenium 与 Cypress< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "05-select.html#sec-5-1" > 三种框架的能力对照< / a > < a class = "toc-a lv3" href = "05-select.html#sec-5-2" > Go 项目为什么常用 Playwright 的 Python 或 Node 绑定< / a > < a class = "toc-a lv3" href = "05-select.html#sec-5-3" > 浏览器与驱动的版本管理< / a > < a class = "toc-a lv3" href = "05-select.html#sec-5-4" > 无头模式与有头模式:调试时怎么切< / a > < a class = "toc-a lv3" href = "05-select.html#sec-5-5" > 选型决策表:按团队现状选,不按热度选< / a > < / div > < a class = "toc-a" href = "06-flow.html" > < i class = "cn" > 6< / i > 核心链路:从登录到下单一遍跑通< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "06-flow.html#sec-6-1" > 冒烟用例的选点:登录、搜索、加购、下单、支付< / a > < a class = "toc-a lv3" href = "06-flow.html#sec-6-2" > 登录态复用: storageState 与 Cookie< / a > < a class = "toc-a lv3" href = "06-flow.html#sec-6-3" > 支付沙箱与外部依赖的挡板< / a > < a class = "toc-a lv3" href = "06-flow.html#sec-6-4" > 用例之间的数据隔离< / a > < a class = "toc-a lv3" href = "06-flow.html#sec-6-5" > 冒烟集的时间预算< / a > < / div > < a class = "toc-a" href = "07-flaky.html" > < i class = "cn" > 7< / i > 稳定性治理:失败归因与重试的正确姿势< / a > < div class = "subnav" > < a class = "toc-a lv3" href = "07-flaky.html#sec-7-1" > 三类失败:真缺陷、环境问题、用例自身< / a > < a class = "toc-a lv3" href = "07-flaky.html#sec-7-2" > 归因流程:从 trace 与截图开始< / a > < a class = "toc-a lv3" href = "07-flaky.html#sec-7-3" > 重
< div class = "side-foot" >
< a class = "btn" href = "index.html" > ← 模块目录< / a >
< a class = "btn" href = "../../index.html" > 学习路径< / a >
< / div >
< / aside >
< div class = "mask" id = "mask" > < / div >
< main class = "main-col" >
< article >
< div class = "modhero" >
< span class = "mh-no" > 阶段 2 · 自动化 · 模块 4 / 6< / span >
< h1 > UI 自动化: Playwright 与 Selenium< / h1 >
< p class = "mh-sub" > 元素定位 · 等待机制 · PO 模式 · 稳定性治理< / p >
< div class = "mh-meta" >
< span > 共 < b > 13< / b > 章< / span >
< span > < b > 60< / b > 个小节< / span >
< span > 约 < b > 66< / b > 千字< / span >
< span > 建议投入 24– 32 小时< / span >
< / div >
< / div >
< p class = "lead" >
< b > 模块定位:< / b > 阶段 2 的第 4 个模块, 也是性价比争议最大的一层。UI 自动化的失败几乎都来自两件事:定位写歪了、等待写错了。学它的目的不是追求覆盖率,而是知道它在哪一段划得来、怎么让它连续跑十天不红。< br > < br > < b > 学完之后你应该能:< / b > 用 Playwright 写出带自动等待、页面对象与失败录屏 / trace 的核心链路冒烟用例,并对每一次失败给出归因(真缺陷 / 环境问题 / 用例自身);能说清哪些用例值得上 UI 自动化、哪些必须留在人工。< br > < br > < b > 学习方式:< / b > 先把定位与等待这两件事做对,再谈框架。选择器散落在用例里,写多少条都会烂掉;先跟开发谈成 data-testid 约定,再动手写第一个页面对象。
< / p >
< h2 id = "chapters-list" > 章节目录< / h2 >
< ol class = "chaplist" >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 1< / span >
< a class = "ci-title" href = "01-why.html" > UI 自动化到底该覆盖什么< / a >
< a class = "ci-go" href = "01-why.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "01-why.html#sec-1-1" > 一次「UI 自动化全覆盖」的失败尝试< / a > < a href = "01-why.html#sec-1-2" > 成本结构:写一次,养十次< / a > < a href = "01-why.html#sec-1-3" > 只覆盖冒烟与核心链路的取舍依据< / a > < a href = "01-why.html#sec-1-4" > 这一模块的交付物与验收标准< / a > < a href = "01-why.html#sec-1-5" > 学习路线与练法< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 2< / span >
< a class = "ci-title" href = "02-locate.html" > 元素定位:选择器为什么必须和开发一起定< / a >
< a class = "ci-go" href = "02-locate.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "02-locate.html#sec-2-1" > 定位方式的优先级: testid、语义、CSS、XPath、文本< / a > < a href = "02-locate.html#sec-2-2" > 为什么 XPath 与文本定位最先烂掉< / a > < a href = "02-locate.html#sec-2-3" > data-testid 约定:怎么和开发谈< / a > < a href = "02-locate.html#sec-2-4" > 定位到多个元素:严格模式与调试< / a > < a href = "02-locate.html#sec-2-5" > 定位自查:改一次文案就红说明什么< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 3< / span >
< a class = "ci-title" href = "03-wait.html" > 等待机制: sleep 为什么一定会出事< / a >
< a class = "ci-go" href = "03-wait.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "03-wait.html#sec-3-1" > 三种等待:隐式、显式与自动等待< / a > < a href = "03-wait.html#sec-3-2" > Playwright 的自动等待替你挡掉了什么< / a > < a href = "03-wait.html#sec-3-3" > 显式等待的正确写法:等状态,不等时间< / a > < a href = "03-wait.html#sec-3-4" > 网络等待与页面就绪的判据< / a > < a href = "03-wait.html#sec-3-5" > 从 flaky 到稳定:等待问题的定位方法< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 4< / span >
< a class = "ci-title" href = "04-po.html" > 页面对象模式:把选择器关进一个地方< / a >
< a class = "ci-go" href = "04-po.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "04-po.html#sec-4-1" > 没有页面对象的用例长什么样< / a > < a href = "04-po.html#sec-4-2" > 一个页面的页面对象怎么写< / a > < a href = "04-po.html#sec-4-3" > 组件对象:弹窗、表格与分页< / a > < a href = "04-po.html#sec-4-4" > 断言放哪里:页面对象只封装操作< / a > < a href = "04-po.html#sec-4-5" > 页面对象的过度设计:什么时候不需要它< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 5< / span >
< a class = "ci-title" href = "05-select.html" > 框架选型: Playwright、Selenium 与 Cypress< / a >
< a class = "ci-go" href = "05-select.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "05-select.html#sec-5-1" > 三种框架的能力对照< / a > < a href = "05-select.html#sec-5-2" > Go 项目为什么常用 Playwright 的 Python 或 Node 绑定< / a > < a href = "05-select.html#sec-5-3" > 浏览器与驱动的版本管理< / a > < a href = "05-select.html#sec-5-4" > 无头模式与有头模式:调试时怎么切< / a > < a href = "05-select.html#sec-5-5" > 选型决策表:按团队现状选,不按热度选< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 6< / span >
< a class = "ci-title" href = "06-flow.html" > 核心链路:从登录到下单一遍跑通< / a >
< a class = "ci-go" href = "06-flow.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "06-flow.html#sec-6-1" > 冒烟用例的选点:登录、搜索、加购、下单、支付< / a > < a href = "06-flow.html#sec-6-2" > 登录态复用: storageState 与 Cookie< / a > < a href = "06-flow.html#sec-6-3" > 支付沙箱与外部依赖的挡板< / a > < a href = "06-flow.html#sec-6-4" > 用例之间的数据隔离< / a > < a href = "06-flow.html#sec-6-5" > 冒烟集的时间预算< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 7< / span >
< a class = "ci-title" href = "07-flaky.html" > 稳定性治理:失败归因与重试的正确姿势< / a >
< a class = "ci-go" href = "07-flaky.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "07-flaky.html#sec-7-1" > 三类失败:真缺陷、环境问题、用例自身< / a > < a href = "07-flaky.html#sec-7-2" > 归因流程:从 trace 与截图开始< / a > < a href = "07-flaky.html#sec-7-3" > 重试能掩盖什么、不能掩盖什么< / a > < a href = "07-flaky.html#sec-7-4" > 环境与数据的自愈< / a > < a href = "07-flaky.html#sec-7-5" > 连续 10 次无人值守的达成路径< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 8< / span >
< a class = "ci-title" href = "08-evidence.html" > 失败留痕:截图、录屏与 trace< / a >
< a class = "ci-go" href = "08-evidence.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "08-evidence.html#sec-8-1" > 留痕要留到什么程度< / a > < a href = "08-evidence.html#sec-8-2" > Playwright trace viewer: 一次失败的回放< / a > < a href = "08-evidence.html#sec-8-3" > 截图与录屏的存放、命名与清理< / a > < a href = "08-evidence.html#sec-8-4" > 从留痕到缺陷单:证据怎么附< / a > < a href = "08-evidence.html#sec-8-5" > 浏览器控制台日志与网络记录< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 9< / span >
< a class = "ci-title" href = "09-ci.html" > 接进流水线: UI 自动化每天怎么跑< / a >
< a class = "ci-go" href = "09-ci.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "09-ci.html#sec-9-1" > 触发策略:夜间全量与提测冒烟< / a > < a href = "09-ci.html#sec-9-2" > 无头环境与容器化运行< / a > < a href = "09-ci.html#sec-9-3" > 报告与录像的归档< / a > < a href = "09-ci.html#sec-9-4" > 失败通知与责任人< / a > < a href = "09-ci.html#sec-9-5" > 数据清理与环境复位< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 10< / span >
< a class = "ci-title" href = "10-cross.html" > 多浏览器、多分辨率与移动端 Web< / a >
< a class = "ci-go" href = "10-cross.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "10-cross.html#sec-10-1" > 浏览器矩阵怎么定< / a > < a href = "10-cross.html#sec-10-2" > 视口与分辨率:为什么本地绿线上红< / a > < a href = "10-cross.html#sec-10-3" > 移动端 Web 与模拟器< / a > < a href = "10-cross.html#sec-10-4" > 并行执行与资源竞争< / a > < a href = "10-cross.html#sec-10-5" > 兼容性问题的归因< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 11< / span >
< a class = "ci-title" href = "11-lab.html" > 实操:电商主链路冒烟套件< / a >
< a class = "ci-go" href = "11-lab.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "11-lab.html#sec-11-1" > 任务说明与验收标准< / a > < a href = "11-lab.html#sec-11-2" > 步骤一:搭骨架与登录态复用< / a > < a href = "11-lab.html#sec-11-3" > 步骤二:写页面对象与主链路用例< / a > < a href = "11-lab.html#sec-11-4" > 步骤三: trace、录屏与重试< / a > < a href = "11-lab.html#sec-11-5" > 交付物模板:报告与稳定性记录< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 12< / span >
< a class = "ci-title" href = "12-cheat.html" > 速查表与高频坑< / a >
< a class = "ci-go" href = "12-cheat.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "12-cheat.html#sec-12-1" > 定位与等待速查< / a > < a href = "12-cheat.html#sec-12-2" > 命令、配置与留痕速查< / a > < a href = "12-cheat.html#sec-12-3" > 高频坑与反模式< / a > < / div >
< / li >
< li class = "chap-item" >
< div class = "ci-head" >
< span class = "ci-no" > 13< / span >
< a class = "ci-title" href = "13-checklist.html" > 完成标准与自测< / a >
< a class = "ci-go" href = "13-checklist.html" > 进入 →< / a >
< / div >
< div class = "ci-secs" > < a href = "13-checklist.html#sec-13-1" > 自测题< / a > < a href = "13-checklist.html#sec-13-2" > 验收清单< / a > < / div >
< / li >
< / ol >
< div class = "box tip" >
< span class = "bt" > 怎么用这一模块< / span >
< p > 左侧第一栏是< b > 章节< / b > ,可以在整章之间跳转;第二栏是< b > 本章小节< / b > ,进入某章后会显示该章的内容大纲并跟随滚动高亮。< / p >
< p > 每章结尾都可以用底部的「上一章 / 下一章」连续阅读。每章内部的代码块右上角可以直接复制,点顶栏的「深色 / 浅色」可以切换主题。< / p >
< / div >
< / article >
< nav class = "pager" >
< a class = "prev" href = "../s2-03-api-framework/index.html" > < span class = "k" > ← 上一模块< / span > < span class = "v" > 接口自动化测试框架< / span > < / a >
2026-10-16 18:33:11 +08:00
< a class = "next" href = "../s2-05-mobile-automation/index.html" > < span class = "k" > 下一模块 →< / span > < span class = "v" > 移动端与小程序自动化< / span > < / a >
2026-10-16 15:38:20 +08:00
< / nav >
< p class = "foot" >
UI 自动化: Playwright 与 Selenium · 模块目录< br >
< a href = "../../index.html" > 返回学习路径< / a >
< / p >
< / main >
< / div >
< button id = "toTop" title = "回到顶部" > ↑< / button >
< script src = "../../assets/doc.js" > < / script >
< script src = "../../../../assets/back.js" data-portal-back = "testdev/testdev-learning-path" data-portal-label = "测试开发工程师 › 测试开发从零到成熟学习路径" > < / script >
< / body >
< / html >