跟 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 加 "标准库" 段 + 示例
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""
|
|
wait.py — 智能等待 helpers (Python 版)
|
|
|
|
避免 networkidle 慢等待, 用具体元素 selector (默认 15s, 比 networkidle 30s 快一半).
|
|
"""
|
|
|
|
from .selectors import SEL
|
|
|
|
|
|
def waitSpaReady(page, timeout=15000):
|
|
"""
|
|
等 jnpf SPA home 渲染完 (菜单可见)
|
|
@returns 第一个匹配到的选择器 (供后续 clickMenu 用)
|
|
"""
|
|
for sel in SEL["MENU_ITEM_CANDIDATES"]:
|
|
try:
|
|
page.wait_for_selector(sel, timeout=timeout)
|
|
return sel
|
|
except Exception:
|
|
continue
|
|
return None
|
|
|
|
|
|
def waitTableReady(page, timeout=15000):
|
|
"""
|
|
等 vxe-table 渲染完 (容器或数据行)
|
|
不等 networkidle — jnpf 6.2.0 SPA 长连接 (心跳) 永远不停
|
|
"""
|
|
page.wait_for_selector(
|
|
f'{SEL["TABLE"]}, {SEL["TABLE_ROW"]}',
|
|
timeout=timeout,
|
|
)
|
|
# 给 vxe-table 渲染 + vue diff 一帧时间
|
|
page.wait_for_timeout(300)
|
|
|
|
|
|
def waitFormModalReady(page, timeout=10000):
|
|
"""
|
|
等 modal 弹窗 + 内部 form 字段渲染完
|
|
200ms 缓冲: antd v-model 异步, 字段 placeholder/input 要等下一 tick
|
|
"""
|
|
page.wait_for_selector(SEL["MODAL"], timeout=timeout)
|
|
page.wait_for_selector(
|
|
f'{SEL["MODAL"]} {SEL["FORM_ITEM"]}',
|
|
timeout=timeout,
|
|
)
|
|
page.wait_for_timeout(200)
|
|
|
|
|
|
def waitModalClose(page, timeout=15000):
|
|
"""等 modal 关闭"""
|
|
page.wait_for_selector(SEL["MODAL"], state="hidden", timeout=timeout)
|
|
|
|
|
|
def waitRowCountChange(page, before, delta, timeout=10000):
|
|
"""
|
|
等列表行数变化 (新增/删除后)
|
|
@param before 新增/删除前的行数
|
|
@param delta +1=期待增加, -1=期待减少
|
|
@returns 变化后的行数
|
|
"""
|
|
import time
|
|
expected = before + delta
|
|
start = time.time()
|
|
while time.time() - start < timeout / 1000:
|
|
count = page.locator(SEL["TABLE_ROW"]).count()
|
|
if delta > 0 and count > before:
|
|
return count
|
|
if delta < 0 and count < before:
|
|
return count
|
|
if count == expected:
|
|
return count
|
|
page.wait_for_timeout(200)
|
|
raise RuntimeError(
|
|
f"waitRowCountChange: {timeout}ms 内行数没从 {before} 变到 {expected}"
|
|
)
|