diff --git a/tests/clazz-dual-view.spec.ts b/tests/clazz-dual-view.spec.ts index 99b3f6f..5a9c289 100644 --- a/tests/clazz-dual-view.spec.ts +++ b/tests/clazz-dual-view.spec.ts @@ -7,19 +7,21 @@ async function loginAsTeacher(page: any) { const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' }); await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 }); await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); - await page.waitForTimeout(3000); + // Wait up to 15s for role selection dialog (may not appear if already logged in) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 15_000 }); const items = page.locator('.van-grid-item'); const count = await items.count(); if (count >= 3) { await items.nth(2).click(); // TEACHER role - await page.waitForTimeout(3000); } else { await items.first().click(); - await page.waitForTimeout(3000); } + await page.waitForTimeout(3000); + } catch { + // No role dialog — proceed with default role } } diff --git a/tests/clazz-scheduling.spec.ts b/tests/clazz-scheduling.spec.ts index ef2c368..826d89a 100644 --- a/tests/clazz-scheduling.spec.ts +++ b/tests/clazz-scheduling.spec.ts @@ -15,13 +15,17 @@ async function loginAndGetTokens(page: any) { const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' }); await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 }); await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); - await page.waitForTimeout(3000); + // Wait up to 15s for role selection dialog (may not appear if already logged in) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 15_000 }); // Select first role (TESTER) for data seeding const first = page.locator('.van-grid-item').first(); - if (await first.isVisible().catch(() => false)) { await first.click(); await page.waitForTimeout(3000); } + await first.click(); + await page.waitForTimeout(3000); + } catch { + // No role dialog — proceed with default role } return await getAuthTokens(page); } @@ -31,20 +35,22 @@ async function loginAsTeacher(page: any) { const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' }); await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 }); await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); - await page.waitForTimeout(3000); + // Wait up to 15s for role selection dialog (may not appear if already logged in) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 15_000 }); // Select TEACHER role (index 2 in the grid: 测试员, 学生, 教师, 管理员, 主管教师) const items = page.locator('.van-grid-item'); const count = await items.count(); if (count >= 3) { await items.nth(2).click(); - await page.waitForTimeout(3000); } else { await items.first().click(); - await page.waitForTimeout(3000); } + await page.waitForTimeout(3000); + } catch { + // No role dialog — proceed with default role } return await getAuthTokens(page); } diff --git a/tests/clazz-supervisor-matrix.spec.ts b/tests/clazz-supervisor-matrix.spec.ts index 9e35a35..9a59367 100644 --- a/tests/clazz-supervisor-matrix.spec.ts +++ b/tests/clazz-supervisor-matrix.spec.ts @@ -18,10 +18,11 @@ test.describe('主管老师矩阵视图', () => { const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' }); await page.goto(`/?${q.toString()}`, { waitUntil: 'domcontentloaded', timeout: 60_000 }); await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); - await page.waitForTimeout(3000); + // Wait up to 15s for role selection dialog (may not appear if already logged in) const rs = page.getByText('请选择您的登录身份'); - if (await rs.isVisible().catch(() => false)) { + try { + await rs.waitFor({ state: 'visible', timeout: 15_000 }); const items = page.locator('.van-grid-item'); const count = await items.count(); if (count >= 3) { @@ -30,6 +31,8 @@ test.describe('主管老师矩阵视图', () => { await items.first().click(); } await page.waitForTimeout(3000); + } catch { + // No role dialog — proceed with default role } }