跟 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 加 "标准库" 段 + 示例
39 lines
961 B
Python
39 lines
961 B
Python
"""
|
|
modal.py — 模态框 helpers (Python 版)
|
|
"""
|
|
|
|
from .selectors import SEL
|
|
|
|
|
|
def waitOpen(page, timeout=10000):
|
|
"""等 modal 打开 + form 字段渲染"""
|
|
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 waitClose(page, timeout=15000):
|
|
"""等 modal 关闭"""
|
|
page.wait_for_selector(SEL["MODAL"], state="hidden", timeout=timeout)
|
|
|
|
|
|
def getErrors(page):
|
|
"""拿校验错误文字列表"""
|
|
errs = page.locator(SEL["FORM_ITEM_ERROR"])
|
|
return errs.all_text_contents()
|
|
|
|
|
|
def isOpen(page):
|
|
"""modal 是否可见"""
|
|
return page.locator(SEL["MODAL"]).count() > 0
|
|
|
|
|
|
def getTitle(page):
|
|
"""拿 modal 标题 (e.g. "新增", "编辑", "提示")"""
|
|
title = page.locator(".ant-modal-title").first
|
|
if title.count() == 0:
|
|
return ""
|
|
return (title.text_content() or "").strip()
|