Skip to content
cccskills
FreePublished on GitHub

architecture

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

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

Works withPlaywright
See how to install

Files included (2)

  • SKILL.md4.5 KB
  • references/page-relay-pattern.md2.2 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

架构决策 — POM 分层与 context 共享模式

适用场景

  • 新增角色/端时决定是否引入新基类
  • 判断某组用例要不要共享 page / context
  • 给新成员解释 POM 分层

POM 分层通用骨架

┌─────────────────────────────────────────────┐
│                  tests/ 测试层                │
│  按角色拆分文件:test_<role>_flow.py          │
│  每个测试类继承 Base(或 Role-Base)           │
├─────────────────────────────────────────────┤
│                  pages/ 页面对象层             │
│  Base ← Login ← Landing ← Detail / ...        │
│  通用 Role 用前缀命名:Role<Role><Page>Page   │
├─────────────────────────────────────────────┤
│                  config/ 配置层                │
│  URL、Token、浏览器参数按环境切换              │
├─────────────────────────────────────────────┤
│                  conftest.py Fixture 层        │
│  browser → context → page → Role-specific base │
└─────────────────────────────────────────────┘

数据流向:config → conftest(读取配置创建 fixture) → pages(接收 page 对象) → tests(组合页面对象执行断言)


PageObject 骨架

# 页面名称:<中文名>
from core.base.base_page import BasePage


class <PageName>(BasePage):
    # 定位符常量(类顶部)
    <LOCATOR_CONSTANT> = "<selector>"   # P<0-5>: 说明
    PAGE_IDENTIFIER = "<selector>"      # 页面加载锚点

    # 业务方法(前缀:click_ / fill_ / select_ / get_xxx_text / wait_for_ / is_xxx_visible)
    def click_<action>(self):
        self.click(self.<LOCATOR_CONSTANT>)

    # 页面加载验证(必须实现,放在最后)
    def is_page_loaded(self) -> bool:
        return self.is_visible(self.PAGE_IDENTIFIER)

context 共享模式决策树

一组用例是否满足以下 3 条?
   1. 同一域名(不跨端)
   2. 有统一前置(登录、角色切换…)
   3. 有统一起点页面(可复位)
       │
       ├─ 是(三条全满足)
       │    └→ class 级共享 context
       │       - 用 scope="class" 的 page fixture(实现见 browser-config skill)
       │       - 专用基类:class setup 完成前置;function-scope autouse 复位起点
       │       - 用例末尾必须往返闭合(见 case-round-trip skill)
       │
       └─ 否(任一不满足)
            └→ function 级独立 context
               - 每用例独立 browser.new_context() + new_page()
               - 每用例独立登录

注意事项:

  • ❌ 禁止 session 级跨 class 共享 context(跨 class 职责边界不清)
  • ❌ 禁止同一 class 内跨域(会污染共享 context)
  • 详细规则见 rules/playwright/browser-context.md "浏览器上下文"段

同 class 内跨用例 page 接力模式

同一 class 的多个用例之间接力同一页面状态(避免每个用例重新登录导航)的 实现要点、骨架与适用条件 → references/page-relay-pattern.md

新增 Role 的落地步骤

  1. 决策:用上面的决策树判断新 Role 的用例是否可共享 context
  2. PageObject:以 Role<Role><Page>Page 命名、role_<page> 文件名前缀,继承 BasePage
  3. 基类(若采用 class 级共享):新建 tests/<role>/<role>_base_test.py::<Role>BaseTest 继承 BaseTest,实现登录 + 切换 + 起点断言
  4. 用例:tests/<role>/test_<role>_flow.py::Test<Role>Flow 继承新基类
  5. 文档:在 docs/architecture.md 表中追加一行
  6. 目录:pages/__init__.py 追加新页面导出

决策落地参考

本项目当前的落地情况(具体类名、fixture、起点页面)→ docs/architecture.md。

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

浏览器 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

替换占位定位符为真实选择器(六级优先级)。触发:替换定位符、locator、selector、定位失败、元素找不到、DOM 分析。

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