一键导入
architecture
POM layering and context sharing decision tree. Trigger: architecture, layering, POM, Page Object, base class design, add new role.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
POM layering and context sharing decision tree. Trigger: architecture, layering, POM, Page Object, base class design, add new role.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | architecture |
| description | POM layering and context sharing decision tree. Trigger: architecture, layering, POM, Page Object, base class design, add new role. |
┌─────────────────────────────────────────────┐
│ tests/ Test Layer │
│ Split by role: test_<role>_flow.py │
│ Each test class inherits Base (or Role-Base) │
├─────────────────────────────────────────────┤
│ pages/ Page Object Layer │
│ Base ← Login ← Landing ← Detail / ... │
│ Generic role prefix: Role<Role><Page>Page │
├─────────────────────────────────────────────┤
│ config/ Config Layer │
│ URL, Token, browser params switch by env │
├─────────────────────────────────────────────┤
│ conftest.py Fixture Layer │
│ browser → context → page → Role-specific base │
└─────────────────────────────────────────────┘
Data flow: config → conftest (read config, create fixtures) → pages (receive page object) → tests (compose page objects and execute assertions)
# Page name: <Page Name>
from pages.base_page import BasePage
class <PageName>(BasePage):
# Locator constants (at top of class)
<LOCATOR_CONSTANT> = "<selector>" # P<0-5>: description
PAGE_IDENTIFIER = "<selector>" # Page load anchor
# Business methods (prefix: click_ / fill_ / select_ / get_xxx_text / wait_for_ / is_xxx_visible)
def click_<action>(self):
self.click(self.<LOCATOR_CONSTANT>)
# Page load verification (must implement, place last)
def is_page_loaded(self) -> bool:
return self.is_visible(self.PAGE_IDENTIFIER)
Does a set of test cases satisfy all 3 conditions?
1. Same domain (no cross-endpoint)
2. Has unified precondition (login, role switch...)
3. Has unified starting page (can be reset)
│
├─ Yes (all 3 satisfied)
│ └→ Class-level shared context
│ - Use scope="class" page fixture (implementation in browser-config skill)
│ - Dedicated base class: class setup completes precondition; function-scope autouse resets start page
│ - Test cases must be round-trip closed (see case-round-trip skill)
│
└─ No (any condition not met)
└→ Function-level independent context
- Each test case has independent browser.new_context() + new_page()
- Each test case logs in independently
Notes:
Scenario: Multiple test cases in the same class form a linear flow chain, where the next test case starts where the previous one ended, without needing to log in from scratch.
test_a (search course)
↓ page stays on search results
test_b (click course → new tab opens course home)
↓ new tab saved as class attribute
test_c (continue operating on course home)
↓ use page from class attribute directly
_login_setup to no-op, share via class_page + request.cls.pagetype(self).<attr> = new_page); subsequent tests access via self.<attr>For the implementation of the
class_pagefixture, see browser-config "Fixture Layer Template".
class TestSomeFlow(BaseTest):
@pytest.fixture(autouse=True)
def _login_setup(self):
yield # no-op, overrides parent
@pytest.fixture(scope="class", autouse=True)
def _shared_setup(self, class_page, token, request):
login_page = LoginPage(class_page)
login_page.login_with_token(BASE_URL, token)
request.cls.page = class_page
def test_step_1(self):
... # self.page already injected by _shared_setup, class-level shared
def test_step_2(self):
new_page = some_page.click_open_new_tab()
type(self).detail_page = new_page # save to class attribute for later tests
def test_step_3(self):
detail = SomeDetailPage(self.detail_page) # direct relay
...
Role<Role><Page>Page, file name prefix role_<page>, inherit BasePagetests/<role>/<role>_base_test.py::<Role>BaseTest inheriting BaseTest, implement login + switch + start page assertiontests/<role>/test_<role>_flow.py::Test<Role>Flow inherits the new base classpages/__init__.pyFor the current project's implementation (specific class names, fixtures, start pages) → docs/architecture.md.
Incrementally add regression test points to an existing PageObject. Trigger: add test point, add regression point, add test point, increase coverage, extend page methods.
Browser viewport / headless / timeout layered configuration. Trigger: viewport, browser config, navigation timeout, headless, slow_mo, incognito.
Under a shared page, a test case that leaves the start page must return via the UI and assert. Trigger: round-trip closure, case round trip, reset timeout, scope shared page.
AST knowledge graph: change review, exploration, debugging, refactoring. Trigger: knowledge graph, code review, impact analysis, blast radius, refactoring.
One-click generation of PageObject + matching tests. Trigger: new page, generate page, gen page, create page, add page object.
Replace placeholder locators with real selectors (six-level priority). Trigger: replace locator, locator, selector, locator failed, element not found, DOM analysis.