本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
/**
|
|
* _helpers/wait.ts — 智能等待 helpers (避免 networkidle 慢等待)
|
|
*
|
|
* jnpf 6.2.0 SPA 特点:
|
|
* - vue-router 跳转不触发整页 reload, networkidle 经常迟迟不到
|
|
* - 业务页 "渲染完" 的稳信号是某个特定元素出现 (菜单/表格行/弹窗)
|
|
*
|
|
* 原则:
|
|
* - 用 page.waitForSelector(具体元素) 代替 waitForLoadState('networkidle')
|
|
* - 默认 15s timeout, 比 networkidle 30s 快很多
|
|
* - 给 form 渲染留 500ms 缓冲 (antd v-model 异步)
|
|
*/
|
|
|
|
import type { Page } from '@playwright/test'
|
|
import { SEL } from './selectors'
|
|
|
|
/**
|
|
* 等 jnpf SPA home 渲染完 (菜单可见)
|
|
* @returns 第一个匹配到的选择器 (供后续 clickMenu 用)
|
|
*/
|
|
export async function waitSpaReady(
|
|
page: Page,
|
|
timeout = 15_000,
|
|
): Promise<string | null> {
|
|
for (const sel of SEL.MENU_ITEM_CANDIDATES) {
|
|
try {
|
|
await page.waitForSelector(sel, { timeout })
|
|
return sel
|
|
} catch {
|
|
continue
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
/**
|
|
* 等 vxe-table 渲染完 (容器或数据行)
|
|
* 不等 networkidle — jnpf 6.2.0 SPA 长连接 (心跳) 永远不停
|
|
*/
|
|
export async function waitTableReady(page: Page, timeout = 15_000) {
|
|
await page.waitForSelector(
|
|
`${SEL.TABLE}, ${SEL.TABLE_ROW}`,
|
|
{ timeout },
|
|
)
|
|
// 给 vxe-table 渲染 + vue diff 一帧时间
|
|
await page.waitForTimeout(300)
|
|
}
|
|
|
|
/**
|
|
* 等 modal 弹窗 + 内部 form 字段渲染完
|
|
* 500ms 缓冲: antd v-model 异步, 字段 placeholder/input 要等下一 tick
|
|
*/
|
|
export async function waitFormModalReady(
|
|
page: Page,
|
|
timeout = 10_000,
|
|
) {
|
|
await page.waitForSelector(SEL.MODAL, { timeout })
|
|
// 等 modal 内至少 1 个 form-item 渲染
|
|
await page.waitForSelector(`${SEL.MODAL} ${SEL.FORM_ITEM}`, {
|
|
timeout,
|
|
})
|
|
await page.waitForTimeout(200)
|
|
}
|
|
|
|
/**
|
|
* 等 modal 关闭
|
|
*/
|
|
export async function waitModalClose(
|
|
page: Page,
|
|
timeout = 15_000,
|
|
) {
|
|
await page.waitForSelector(SEL.MODAL, {
|
|
state: 'hidden',
|
|
timeout,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 等列表行数变化 (新增/删除后)
|
|
* @param before 新增/删除前的行数
|
|
* @param delta +1=期待增加, -1=期待减少
|
|
*/
|
|
export async function waitRowCountChange(
|
|
page: Page,
|
|
before: number,
|
|
delta: 1 | -1,
|
|
timeout = 10_000,
|
|
) {
|
|
const expected = before + delta
|
|
const start = Date.now()
|
|
while (Date.now() - start < timeout) {
|
|
const count = await page.locator(SEL.TABLE_ROW).count()
|
|
if (delta > 0 ? count > before : count < before) return count
|
|
if (count === expected) return count
|
|
await page.waitForTimeout(200)
|
|
}
|
|
throw new Error(
|
|
`waitRowCountChange: ${timeout}ms 内行数没从 ${before} 变到 ${expected}`,
|
|
)
|
|
}
|