diff --git a/tests/course-package-store.spec.ts b/tests/course-package-store.spec.ts index 174bb09..cc7b4c5 100644 --- a/tests/course-package-store.spec.ts +++ b/tests/course-package-store.spec.ts @@ -258,12 +258,25 @@ async function loginAsStudent(page: any, moicenUnionid: string) { const firstOrgCell = page.locator('#app .van-cell-group .van-cell').first(); if (await firstOrgCell.isVisible({ timeout: 10_000 }).catch(() => false)) { await firstOrgCell.click(); - // Navigate to a known student page to settle SPA state after org switch - await page.waitForURL(/\/student\/|\//, { timeout: 15_000 }); - await page.goto('/student/profile', { waitUntil: 'domcontentloaded', timeout: 60_000 }); - await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); + await page.waitForTimeout(3000); } } + + // Ensure we're on a settled student page + const currentPath = new URL(page.url()).pathname; + if (!currentPath.startsWith('/student/')) { + await page.goto('/student/profile', { + waitUntil: 'domcontentloaded', + timeout: 60_000, + }); + await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); + } + + // Skip if session lost + if (await page.getByText('请返回微信小程序完成登录').isVisible().catch(() => false)) { + return false; + } + return true; }