Skip to content
cccskills
FreePublished on GitHub

page-load-assertion

is_page_loaded() 四种验证模式与调用层级。触发:页面断言、is_page_loaded、page loaded、页面加载验证。

The English summary is being prepared. Showing the original description.

See how to install

Files included (2)

  • SKILL.md4.8 KB
  • references/blank-screen-detection.md3.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Page Load Assertion — 页面加载断言方法论

核心思路

页面"正常"的判断不是检查 HTTP 状态码,而是验证用户能看到的关键元素确实渲染出来了。通过每个 PageObject 的 is_page_loaded() 方法统一实现。


is_page_loaded() 的四种验证模式

按严格程度从低到高:

模式 A:单元素验证(最简单)

检查该页面独有的标志性容器是否可见。适用于结构简单、一个元素就能区分的页面:

PAGE_CONTAINER = "css=.feature-container"    # P3

def is_page_loaded(self) -> bool:
    return self.is_visible(self.PAGE_CONTAINER)

模式 B:双元素 AND 组合(推荐默认)

容器 + 内容 双重验证,确保"页面骨架到位 + 数据渲染完成":

PAGE_CONTAINER = "css=.feature-container"    # P3
PAGE_TITLE = "text=欢迎使用"                  # P1

def is_page_loaded(self) -> bool:
    return self.is_visible(self.PAGE_CONTAINER) and self.is_visible(self.PAGE_TITLE)

模式 C:多元素 + 激活态验证(最严格)

在结构和内容基础上,还验证当前 UI 状态(如某个 tab 处于 active)。适用于承担"起点状态判断"语义的页面:

PAGE_TITLE = "css=span.page-title"                                    # P3
TAB_BAR = "css=ul.tab-bar"                                            # P3
DEFAULT_TAB_ACTIVE = "css=ul.tab-bar li.tab.active >> text=默认Tab"    # P3+P1

def is_page_loaded(self) -> bool:
    return (
        self.is_visible(self.PAGE_TITLE)
        and self.is_visible(self.TAB_BAR)
        and self.is_visible(self.DEFAULT_TAB_ACTIVE)
    )

注意:状态类 selector(.active / aria-selected 等)必须配 text 锁定,否则切换 tab 后 .active 跟随新激活对象漂移。

模式 D:委托给语义方法

把验证逻辑提取为有业务含义的方法名,便于 setup fixture 中单独调用:

def is_page_loaded(self) -> bool:
    return self.is_login_success()

def is_login_success(self) -> bool:
    return self.is_visible(self.SUCCESS_FLAG) and self.is_visible(self.NAV_LIST)

模式选择决策树

新页面需要 is_page_loaded()
│
├─ 页面结构简单,一个独有容器即可区分?
│  └─ 是 → 模式 A(单元素)
│
├─ 需要确认内容也渲染到位?
│  └─ 是 → 模式 B(容器 + 内容,推荐默认)
│
├─ 该页面是复位 fixture 的起点,需要判断 UI 状态?
│  └─ 是 → 模式 C(多元素 + 激活态)
│
├─ 验证逻辑在 setup 中也需要单独调用?
│  └─ 是 → 模式 D(委托给语义方法)
│
└─ 容器可能存在但内容未渲染(SPA 子 Tab 切换 / 异步加载)?
   └─ 是 → 模式 E(JS evaluate 检查子元素数量)

验证元素的选择原则

原则说明
选该页面独有的元素不选通用 header/footer,选只有这个页面才有的容器或文本
优先选结构性容器如 .feature-container、.detail-wrapper,页面骨架不易变
文本元素锁定业务语义如 text=欢迎使用,确认内容渲染到位
状态类 selector 配 text.active 会随操作漂移,必须加 >> text=具体文本 锁定
不选动态数据具体数字、用户名等因数据变化导致断言不稳定

断言目标的三级稳定性

核心原则:优先选模板级文本(页面框架固定标题),禁止选数据级内容(动态计数、日期)。多视图场景中每个断言目标须同时满足「模板级 + 视图独占」。

完整规则与反例/正例 → assertion-patterns.md "断言目标稳定性"章节。

模式 E:白屏检测 + 空数据 vs 有数据 三态判断

SPA 中容器 div 可能存在且 is_visible 为真,但内部组件未挂载(白屏)—— 此时模式 A/B 会误判为正常。该场景需要三态判断,细节较多且只在 SPA 下适用。

按需展开 → references/blank-screen-detection.md

调用层级

  1. class setup:登录后 assert home.is_page_loaded(), "首页加载失败"
  2. function reset:if not self.home.is_page_loaded(): click_nav_home(); assert ...
  3. 用例体:每次跳转后 assert target.is_page_loaded(), "<页面>加载失败"

规则约束

  1. 每个 PageObject 必须实现 is_page_loaded()——返回 bool,放在类的最后一个方法
  2. is_page_loaded() 内部只用 is_visible() 组合,不抛异常

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

为已有 PageObject 增量添加回归测试点。触发:新增测试点、添加回归点、add test point、增加覆盖、扩展页面方法。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

POM 分层与 context 共享决策树。触发:架构、分层、POM、Page Object、基类设计、新增角色。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

浏览器 viewport / headless / 超时分层配置。触发:viewport、浏览器配置、导航超时、headless、slow_mo、incognito。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

共享 page 下用例离开起点后必须 UI 返回并断言。触发:往返闭合、case round trip、复位超时、scope 共享 page。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

AST 知识图谱:变更审查、探索、调试、重构。触发:知识图谱、代码审查、影响分析、爆炸半径、重构。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

一键生成 PageObject + 配套测试。触发:新增页面、生成页面、gen page、create page、添加页面对象。

The English summary is being prepared. Showing the original description.

DanielSuo117/velocitai159Updated Sep 28, 2026

See all skills by DanielSuo117

Report a problem with this skill