跟 dacli/tests/e2e/_helpers/ 一一对应 (TS 已 v17 提交), API 对齐:
- selectors.py: SEL/formItemByLabel/rowAction (147 行)
- wait.py: waitSpaReady/waitTableReady/waitFormModalReady/waitModalClose/waitRowCountChange
- nav.py: clickMenu/expandCategory (精确匹配 + SPA 路由触发)
- form.py: fillByLabel/selectByLabel/fillDateByLabel/fillTextareaByLabel/
fillNumberByLabel/saveModal/closeModal
- table.py: countRows/findRow/clickRowAction/getTotalText/getTotalCount/clickAdd
- modal.py: waitOpen/waitClose/getErrors/isOpen/getTitle
- __init__.py: 聚合导出, camelCase API 与 TS 版一致
Python 528 行, TS 800 行 (TS 多 ~50% 因为类型注解 + 显式 interface)
用法 (Python 脚本):
from lib import clickMenu, fillByLabel, saveModal, countRows, clickAdd
用法 (TypeScript spec):
import { clickMenu, fillByLabel, ... } from './_helpers'
后续 (留待 v18+):
- 用新库重写 jnpf_browser_e2e.py / jnpf_client.py (去重)
- ssw-e2e-test/SKILL.md 加 "标准库" 段 + 示例
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
"""
|
|
selectors.py — JNPF 6.2.0 通用选择器常量 (Python 版)
|
|
|
|
与 dacli/tests/e2e/_helpers/selectors.ts 字段一一对应, 改 jnpf 版本改这两处即可。
|
|
"""
|
|
|
|
# 选择器常量
|
|
SEL = {
|
|
# ===== 登录页 =====
|
|
"LOGIN_ACCOUNT": "#form_item_account",
|
|
"LOGIN_PASSWORD": "#form_item_password",
|
|
"LOGIN_SUBMIT": 'button:has-text("登 录")',
|
|
|
|
# ===== 侧边栏菜单 (jnpf 6.2.0 扁平 + 偶尔嵌套) =====
|
|
"MENU_ITEM": ".jnpf-menu-item",
|
|
"MENU_SUB": ".jnpf-sub-menu",
|
|
"MENU_SUB_TITLE": ".jnpf-sub-menu-content__title",
|
|
"MENU_SUB_CONTENT": ".jnpf-sub-menu-content",
|
|
"MENU_ITEM_CANDIDATES": [
|
|
".jnpf-menu-item",
|
|
".ant-menu-item",
|
|
'[class*="menu-item"]',
|
|
],
|
|
|
|
# ===== 模态框 =====
|
|
"MODAL": ".ant-modal",
|
|
"MODAL_CONFIRM": ".ant-modal-confirm",
|
|
"MODAL_CONFIRM_BTNS": ".ant-modal-confirm-btns",
|
|
"MODAL_PRIMARY": (
|
|
'.ant-modal-confirm-btns button.ant-btn-primary, '
|
|
'.ant-modal button.ant-btn-primary, '
|
|
'.ant-modal button:has-text("保 存"), '
|
|
'.ant-modal button:has-text("确 定")'
|
|
),
|
|
"MODAL_CLOSE": '.ant-modal button:has-text("关 闭")',
|
|
"MODAL_CANCEL": '.ant-modal button:has-text("取 消")',
|
|
|
|
# ===== 表单 =====
|
|
"FORM_ITEM": ".ant-form-item",
|
|
"FORM_ITEM_LABEL": ".ant-form-item-label label",
|
|
"FORM_ITEM_REQUIRED": ".ant-form-item-required",
|
|
"FORM_ITEM_ERROR": ".ant-form-item-explain-error",
|
|
|
|
# ===== 输入控件 =====
|
|
"INPUT": "input",
|
|
"TEXTAREA": "textarea",
|
|
"SELECT": ".ant-select",
|
|
"SELECT_DROPDOWN": ".ant-select-dropdown:visible",
|
|
"SELECT_ITEM": ".ant-select-item-option",
|
|
"PICKER": ".ant-picker input",
|
|
|
|
# ===== 表格 (vxe-table 4.x) =====
|
|
"TABLE": ".vxe-table",
|
|
"TABLE_ROW": ".vxe-body--row",
|
|
"TABLE_PAGER_TOTAL": ".vxe-pager--total, .pager-count, .jnpf-pagination__total",
|
|
|
|
# ===== 通用按钮 =====
|
|
"BTN_PRIMARY": "button.ant-btn-primary",
|
|
"BTN_NEW": 'button:has-text("新 增"), button:has-text("新增")',
|
|
"BTN_EDIT": (
|
|
'a:has-text("编 辑"), a:has-text("编辑"), '
|
|
'button:has-text("编 辑"), button:has-text("编辑")'
|
|
),
|
|
"BTN_DELETE": (
|
|
'a:has-text("删 除"), a:has-text("删除"), '
|
|
'button:has-text("删 除"), button:has-text("删除")'
|
|
),
|
|
}
|
|
|
|
|
|
def formItemByLabel(page, label, scope=None):
|
|
"""
|
|
找含 label 文本的 form-item (在 modal 或其他容器内)
|
|
用法: formItemByLabel(page, '申请人姓名') → Locator
|
|
"""
|
|
if scope is None:
|
|
scope = SEL["MODAL"]
|
|
return page.locator(
|
|
f'{scope} {SEL["FORM_ITEM"]}:has({SEL["FORM_ITEM_LABEL"]}:has-text("{label}"))'
|
|
)
|
|
|
|
|
|
def rowAction(row, action):
|
|
"""
|
|
找行的操作按钮 (jnpf 模板常用 a/button + "编辑/删除")
|
|
用法: rowAction(row, '编 辑') → Locator
|
|
"""
|
|
return row.locator(f'a:has-text("{action}"), button:has-text("{action}")')
|