diff --git a/tests/department-single-transparent.spec.ts b/tests/department-single-transparent.spec.ts index 5fb361b..4945403 100644 --- a/tests/department-single-transparent.spec.ts +++ b/tests/department-single-transparent.spec.ts @@ -45,12 +45,14 @@ async function loginAndDismissSelectors(page: any) { console.log('[DeptTest] clicked org cell'); await page.waitForTimeout(3_000); } else if (path === '/') { + // 用 waitFor 避免 SPA 路由守卫异步加载角色时的竞态(isVisible 可能返回 false) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 10_000 }); await page.locator('.van-grid-item').first().click(); console.log('[DeptTest] clicked role'); await page.waitForTimeout(3_000); - } else { + } catch { console.log('[DeptTest] at / but no role selector'); // 无角色选择器 → 当前用户角色已自动选中(1个活跃角色)。 // chooseRole 内部调用 router.push('/role/profile') 是异步的,