fix(e2e): 教学资源链从 /course/summary 建立上下文;fixtures 捕获 console/vConsole 与 OrgSwitchDebug
Made-with: Cursor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { test, expect, type Page } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { expect, test } from './fixtures';
|
||||
|
||||
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
|
||||
|
||||
@@ -35,17 +36,46 @@ function extractOrgIdFromTokenPayload(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** 课程体系列表壳:搜索框或 van-search(不同构建/加载时机下占位符可能尚未绑定) */
|
||||
async function waitForCourseListShell(page: Page) {
|
||||
await Promise.race([
|
||||
page
|
||||
.getByPlaceholder('请输入课程体系名称搜索')
|
||||
.waitFor({ state: 'visible', timeout: 90_000 }),
|
||||
page.locator('.van-search').first().waitFor({
|
||||
state: 'visible',
|
||||
timeout: 90_000,
|
||||
}),
|
||||
]);
|
||||
/**
|
||||
* 教学资源相关任意壳层可见即可(`/course/summary` 入口链或课程体系列表)。
|
||||
* CI 上课程索引偶发长时间无搜索框;summary 页 Cell 更稳定。
|
||||
*/
|
||||
async function waitForCourseRealmVisible(page: Page) {
|
||||
const deadline = Date.now() + 95_000;
|
||||
while (Date.now() < deadline) {
|
||||
if (
|
||||
await page.getByRole('link', { name: '课程体系' }).isVisible().catch(() => false)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
await page
|
||||
.locator('.van-cell')
|
||||
.filter({ hasText: /^课程体系$/ })
|
||||
.first()
|
||||
.isVisible()
|
||||
.catch(() => false)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
await page
|
||||
.getByPlaceholder('请输入课程体系名称搜索')
|
||||
.isVisible()
|
||||
.catch(() => false)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
await page.locator('.van-search').first().isVisible().catch(() => false)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await page.waitForTimeout(400);
|
||||
}
|
||||
throw new Error(
|
||||
`教学资源壳层未出现:${page.url()}`
|
||||
);
|
||||
}
|
||||
|
||||
async function establishSession(page: Page) {
|
||||
@@ -74,7 +104,7 @@ async function establishSession(page: Page) {
|
||||
*/
|
||||
async function resolveOrgContextForCoursePage(page: Page) {
|
||||
for (let attempt = 0; attempt < 6; attempt++) {
|
||||
await page.goto('/course', {
|
||||
await page.goto('/course/summary', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 90_000,
|
||||
});
|
||||
@@ -108,17 +138,20 @@ async function resolveOrgContextForCoursePage(page: Page) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (page.url().includes('/course')) {
|
||||
if (
|
||||
page.url().includes('/course/summary') ||
|
||||
page.url().includes('/course')
|
||||
) {
|
||||
await page.waitForLoadState('networkidle', { timeout: 60_000 }).catch(() => {});
|
||||
await waitForCourseListShell(page);
|
||||
await waitForCourseRealmVisible(page);
|
||||
return;
|
||||
}
|
||||
|
||||
// 守卫可能暂时送回首页「进入工作台」等,下一循环再深链 `/course`
|
||||
// 守卫可能暂时送回首页「进入工作台」等,下一循环再深链
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'resolveOrgContextForCoursePage: 无法在合理步数内进入 /course(可能被重定向离开课程体系)'
|
||||
'resolveOrgContextForCoursePage: 无法在合理步数内进入教学资源链(/course/summary 等)'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -234,7 +267,12 @@ test.describe('多机构数据隔离(会话与 token)', () => {
|
||||
|
||||
await resolveOrgContextForCoursePage(page);
|
||||
|
||||
await waitForCourseListShell(page);
|
||||
await page.goto('/course', {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 90_000,
|
||||
});
|
||||
await expect(page.locator('#app')).toBeVisible({ timeout: 90_000 });
|
||||
await waitForCourseRealmVisible(page);
|
||||
|
||||
await expect(
|
||||
page.getByText('请求失败,点击重新加载')
|
||||
|
||||
Reference in New Issue
Block a user