跟 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 加 "标准库" 段 + 示例
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
"""
|
|
table.py — vxe-table 操作 helpers (Python 版)
|
|
"""
|
|
|
|
import re
|
|
|
|
from .selectors import SEL
|
|
|
|
|
|
def countRows(page):
|
|
"""数 vxe-table 数据行数"""
|
|
return page.locator(SEL["TABLE_ROW"]).count()
|
|
|
|
|
|
def findRow(page, text):
|
|
"""找含文本的行 (返回 Locator, 可链式 .first / .nth)"""
|
|
return page.locator(f'{SEL["TABLE_ROW"]}:has-text("{text}")')
|
|
|
|
|
|
def clickRowAction(page, rowText, action):
|
|
"""
|
|
在指定行点操作 (编辑/删除)
|
|
找不到行或按钮抛错 (不静默, 显式失败)
|
|
"""
|
|
row = findRow(page, rowText).first
|
|
if row.count() == 0:
|
|
raise RuntimeError(f'clickRowAction: 找不到含 "{rowText}" 的行')
|
|
btn = row.locator(
|
|
f'a:has-text("{action}"), button:has-text("{action}")'
|
|
).first
|
|
if btn.count() == 0:
|
|
raise RuntimeError(
|
|
f'clickRowAction: 行 "{rowText}" 无 "{action}" 按钮'
|
|
)
|
|
btn.click()
|
|
|
|
|
|
def getTotalText(page):
|
|
"""拿分页总数文字 (e.g. "共 3 条")"""
|
|
footer = page.locator(SEL["TABLE_PAGER_TOTAL"]).first
|
|
if footer.count() > 0:
|
|
return footer.text_content() or ""
|
|
# fallback: 找含"共"和"条" 的文字
|
|
el = page.locator("text=/共\\s*\\d+\\s*条/").first
|
|
try:
|
|
return el.text_content() or ""
|
|
except Exception:
|
|
return ""
|
|
|
|
|
|
def getTotalCount(page):
|
|
"""解析分页总数文字里的数字, e.g. "共 3 条" → 3"""
|
|
text = getTotalText(page)
|
|
m = re.search(r"(\d+)", text)
|
|
return int(m.group(1)) if m else 0
|
|
|
|
|
|
def clickAdd(page):
|
|
"""点列表页"新增"按钮 (列表顶部)"""
|
|
btn = page.locator(SEL["BTN_NEW"]).first
|
|
if btn.count() == 0:
|
|
raise RuntimeError('clickAdd: 列表页找不到"新增"按钮')
|
|
btn.click()
|