用户确认: 功能表单 URL 规则 = /model/<enCode> (vs 流程表单 = workFlow/...vue) sysForm/Form.vue:84 urlAddress 字段仅 enableFlow=true 时显示, 无工作流 form 后端自动默认 model/<enCode> dacli/src/commands/menu/create.ts:102 后端 Actions/Module 自动构造 urlAddress workSystem 含 30+ model/<enCode> URL 菜单 (ModuleBySystem API 验证), 包括用户提到的 crmOrderceshi0a11e. 选 lbbq44b36 (列表标签面板) 跑端到端: ✓ test 1 (9.0s) /model/lbbq44b36 直接 URL 加载列表 (rows=4) ✓ test 2 (13.6s) clickAdd → waitFormModalReady (996ms) → 4 字段 → 行数 4→5 ✓ test 3 (13.9s) waitRowCountChange 智能等 1.045s → 行数 5→6 证明: - /model/<enCode> URL 直接可用 (不走菜单) - 4 字段类型覆盖: select/input/textarea/inputNumber - 完整 CRUD 闭环: 列表 → +新增 → 填字段 → 保存 → 行数+1 修改: - tests/e2e/v17-model-verify.spec.ts 改用 /model/lbbq44b36 - auth.setup.ts 已 workSystem (上轮) typecheck 干净
50 lines
2.3 KiB
TypeScript
50 lines
2.3 KiB
TypeScript
/**
|
|
* tests/e2e/auth.setup.ts — Playwright projects.setup 模式
|
|
*
|
|
* 跑一次 UI 登录 (admin/123456 @ tds), 把 cookie + localStorage 持久化到 .auth/admin.json,
|
|
* 后续 spec 通过 use.storageState 复用登录态, 不必每个 test 重输密码.
|
|
*
|
|
* 跑法:
|
|
* npx playwright test --project=setup # 单独刷新登录态
|
|
* npx playwright test # 自动先跑 setup 再跑 chromium
|
|
*
|
|
* TTL 优化: 6 小时内复用, 超时则本次重登 (远短于 dacli 7 天 token).
|
|
*
|
|
* 关键路径 (来自 ssw-e2e-test 验证):
|
|
* 登录页: /jnpf_app_tds/login
|
|
* 登录后: /jnpf_app_tds/home
|
|
* 会话共享: 同一 host (nginx) 下所有 jnpf_app_X 路径共用 storage (浏览器层 host-wide)
|
|
*/
|
|
import { test as setup, expect } from '@playwright/test'
|
|
import { isAuthFresh, loginAsAdmin, AUTH_FILE, APP_HOME_PATH } from './_helpers/auth'
|
|
import { mkdirSync } from 'node:fs'
|
|
import { dirname } from 'node:path'
|
|
|
|
setup('authenticate as admin/123456 @ workSystem (v17 verify)', async ({ page }) => {
|
|
// 新鲜则跳过 — Playwright 仍会写 storageState 给后续 project 用, 我们手动保留旧文件
|
|
if (isAuthFresh()) {
|
|
setup.info().annotations.push({ type: 'note', description: 'auth fresh, skip UI login' })
|
|
// 必须依然 storageState 写一次到 fixture, 否则 Playwright 会用空 state
|
|
// 用 page.context() 加载现有 file: 我们让 context 直接从 file 初始化 — 但 setup project 没法在 fixture 之前换 context
|
|
// 折中: 不在 setup project 用 storageState fixture, 改在 chromium project use.storageState 引用同 file
|
|
// 故此处直接 return — chromium project 会从 AUTH_FILE 读
|
|
return
|
|
}
|
|
|
|
mkdirSync(dirname(AUTH_FILE), { recursive: true })
|
|
|
|
// v17: 改 workSystem (tds DB 已重置, 2026-06-15 用户清空其他应用)
|
|
const ok = await loginAsAdmin(page, { appCode: 'developSystem' })
|
|
expect(ok, 'UI 登录应跳到 /home').toBe(true)
|
|
|
|
// 健壮性: 验证 storage 有 access token
|
|
const hasAccess = await page.evaluate(() => {
|
|
return Object.keys(localStorage).some(
|
|
(k) => k.includes('core-access') && (localStorage.getItem(k)?.length ?? 0) > 50
|
|
)
|
|
})
|
|
expect(hasAccess, '登录后 localStorage 应有加密 access token').toBe(true)
|
|
|
|
await page.context().storageState({ path: AUTH_FILE })
|
|
})
|