fix(e2e): 机构页就绪判断改为统一轮询

避免 Promise.race 分支 waitFor 超时直接失败,改为 #app 文本与机构 cell 的组合条件轮询。

Made-with: Cursor
This commit is contained in:
2026-04-28 10:52:28 +08:00
parent 381b182e63
commit 62d9829a0c
+15 -11
View File
@@ -221,18 +221,22 @@ test.describe('多机构数据隔离(会话与 token', () => {
test.skip(true, '打开机构页时会话已退回访客态');
}
// 线上壳层不一定是 .main>h4(路由/构建差异);任一就绪即可
await Promise.race([
page.locator('#app').getByText(/请选择机构/).first().waitFor({
state: 'visible',
timeout: 90_000,
// 线上壳层可能存在结构差异;轮询任一机构页就绪信号,避免分支超时互相误杀
await expect
.poll(
async () =>
page.evaluate(() => {
const appRoot = document.querySelector('#app');
if (!appRoot) return false;
const rootText = appRoot.textContent ?? '';
const hasOrgTitle = /请选择机构/.test(rootText);
const hasEmptyHint = rootText.includes('暂无可用机构');
const hasOrgCells = !!appRoot.querySelector('.van-cell-group .van-cell');
return hasOrgTitle || hasEmptyHint || hasOrgCells;
}),
page.getByText('暂无可用机构').waitFor({ state: 'visible', timeout: 90_000 }),
page
.locator('#app .van-cell-group .van-cell')
.first()
.waitFor({ state: 'visible', timeout: 90_000 }),
]);
{ timeout: 90_000, intervals: [500, 1000, 2000] }
)
.toBeTruthy();
if (
await page.getByText('暂无可用机构').isVisible().catch(() => false)