Просмотр исходного кода

✅ test(e2e): improve user management page load waiting strategy

- 优化页面加载等待逻辑,先等待domcontentloaded再等待表格数据
- 增加表格数据加载的显式等待,替换原有的networkidle等待
- 为各元素可见性检查添加更合理的超时时间
- 验证用户表格至少有一行数据加载完成
yourname 2 месяцев назад
Родитель
Сommit
e3676db19e
1 измененных файлов с 14 добавлено и 5 удалено
  1. 14 5
      tests/e2e/pages/admin/user-management.page.ts

+ 14 - 5
tests/e2e/pages/admin/user-management.page.ts

@@ -28,16 +28,25 @@ export class UserManagementPage {
     await this.page.goto('/admin/users');
 
     // 等待页面完全加载 - 使用更可靠的等待条件
-    await this.page.waitForLoadState('networkidle');
+    // 先等待domcontentloaded,然后等待表格数据加载
+    await this.page.waitForLoadState('domcontentloaded');
+
+    // 等待用户表格出现,使用更具体的等待条件
+    await this.page.waitForSelector('h1:has-text("用户管理")', { state: 'visible', timeout: 15000 });
+
+    // 等待表格数据加载完成,而不是等待所有网络请求
+    await this.page.waitForSelector('table tbody tr', { state: 'visible', timeout: 20000 });
+
     await this.expectToBeVisible();
   }
 
   async expectToBeVisible() {
     // 等待页面完全加载,使用更精确的选择器
-    await this.page.waitForSelector('h1:has-text("用户管理")', { state: 'visible', timeout: 15000 });
-    await expect(this.pageTitle).toBeVisible();
-    await expect(this.createUserButton).toBeVisible();
-    await expect(this.userTable).toBeVisible();
+    await expect(this.pageTitle).toBeVisible({ timeout: 15000 });
+    await expect(this.createUserButton).toBeVisible({ timeout: 10000 });
+
+    // 等待至少一行用户数据加载完成
+    await expect(this.userTable.locator('tbody tr').first()).toBeVisible({ timeout: 20000 });
   }
 
   async searchUsers(keyword: string) {