标准库 (dacli/tests/e2e/_helpers/, 6 文件 ~800 行): - selectors.ts: JNPF 6.2.0 通用选择器常量 (SEL/formItemByLabel/rowAction) - wait.ts: 智能等待 (waitSpaReady/waitTableReady/waitFormModalReady/waitRowCountChange) 不用 networkidle, 用具体元素 selector, 默认 15s (vs 30s networkidle) - nav.ts: 菜单导航 (clickMenu 精确匹配 + expandCategory) - form.ts: 表单操作 (fillByLabel/selectByLabel/fillDateByLabel/fillTextareaByLabel/ fillNumberByLabel/saveModal/closeModal) - table.ts: vxe-table 操作 (countRows/findRow/clickRowAction/getTotalText/clickAdd) - modal.ts: 模态框 (waitOpen/waitClose/getErrors/isOpen/getTitle) - index.ts: 聚合导出 - auth.ts: 已存在 (login + storageState 6h TTL) p16 spec 重构: - tests/e2e/p16-ui-real-crud.spec.ts: 226 → 180 行 (-20%) - 用 _helpers 替代内联 selector, 智能等待替代 networkidle - typecheck 通过 已知问题 (与重构无关): - tds_leave 是 webType=1 (仅表单), 无 vxe-table 列表, p16 1st test 失败 - 原版 p16 同样 fail — 测试数据配置问题, 不是 refactor 引入 后续 (Python 镜像 + tds_leave webType 修复) 留 task #22
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
/**
|
|
* _helpers/modal.ts — 模态框 helpers
|
|
*
|
|
* 用法:
|
|
* await waitFormModalReady(page) // 等打开
|
|
* await fillByLabel(...)
|
|
* await saveModal(page) // 触发保存
|
|
* await waitModalClose(page) // 等自动关闭
|
|
* // 或:
|
|
* const errs = await getErrors(page)
|
|
* if (errs.length > 0) throw new Error(errs.join(', '))
|
|
*/
|
|
|
|
import type { Page } from '@playwright/test'
|
|
import { SEL, formItemByLabel } from './selectors'
|
|
|
|
/** 等 modal 打开 + form 字段渲染 */
|
|
export async function waitOpen(page: Page, timeout = 10_000) {
|
|
await page.waitForSelector(SEL.MODAL, { timeout })
|
|
await page.waitForSelector(`${SEL.MODAL} ${SEL.FORM_ITEM}`, {
|
|
timeout,
|
|
})
|
|
await page.waitForTimeout(200)
|
|
}
|
|
|
|
/** 等 modal 关闭 */
|
|
export async function waitClose(page: Page, timeout = 15_000) {
|
|
await page.waitForSelector(SEL.MODAL, {
|
|
state: 'hidden',
|
|
timeout,
|
|
})
|
|
}
|
|
|
|
/** 拿校验错误文字列表 */
|
|
export async function getErrors(page: Page): Promise<string[]> {
|
|
const errs = page.locator(SEL.FORM_ITEM_ERROR)
|
|
return await errs.allTextContents()
|
|
}
|
|
|
|
/** modal 是否可见 */
|
|
export async function isOpen(page: Page): Promise<boolean> {
|
|
return (await page.locator(SEL.MODAL).count()) > 0
|
|
}
|
|
|
|
/** 拿 modal 标题 (e.g. "新增", "编辑", "提示") */
|
|
export async function getTitle(page: Page): Promise<string> {
|
|
const title = page.locator('.ant-modal-title').first()
|
|
if ((await title.count()) === 0) return ''
|
|
return ((await title.textContent()) ?? '').trim()
|
|
}
|