Browse Source

📝 docs(guide): update e2e testing documentation
- add instruction to check test-results/**/error-context.md when e2e tests fail
- add space in e2e command format for consistency

✅ test(e2e): improve dashboard page locators reliability
- use more specific locators for user management and system settings cards to avoid duplicate element issues
- enhance active users and system messages count locators with visibility checks
- increase timeout for element visibility checks to 10000ms

yourname 2 months ago
parent
commit
1a604daf5c
2 changed files with 16 additions and 5 deletions
  1. 2 1
      CLAUDE.md
  2. 14 4
      tests/e2e/pages/admin/dashboard.page.ts

+ 2 - 1
CLAUDE.md

@@ -10,6 +10,7 @@
 - ### Claude Code
 - use pnpm
 - 数据库在同一容器组的另一个容器中,需要运行 psql -h 127.0.0.1 -U postgres 来访问
-- e2e测试平常只运行pnpm test:e2e:chromium就行
+- e2e测试平常只运行 pnpm test:e2e:chromium 就行
+- e2e测试失败时先查看页面结构 test-results/**/error-context.md
 - bmad-core dir is in .bmad-core
 - 必须用中文回答

+ 14 - 4
tests/e2e/pages/admin/dashboard.page.ts

@@ -27,21 +27,31 @@ export class DashboardPage {
   }
 
   async navigateToUserManagement() {
-    await this.userManagementCard.click();
+    // 使用更具体的定位器来避免重复元素问题
+    const userManagementCard = this.page.locator('text=用户管理').first();
+    await userManagementCard.click();
     await this.page.waitForLoadState('networkidle');
   }
 
   async navigateToSystemSettings() {
-    await this.systemSettingsCard.click();
+    // 使用更具体的定位器来避免重复元素问题
+    const systemSettingsCard = this.page.locator('text=系统设置').first();
+    await systemSettingsCard.click();
     await this.page.waitForLoadState('networkidle');
   }
 
   async getActiveUsersCount(): Promise<string> {
-    return await this.activeUsersCard.locator('xpath=following-sibling::div//div[contains(@class, "text-2xl")]').textContent() || '';
+    // 使用更可靠的定位器来获取活跃用户统计数字
+    const countElement = this.page.locator('text=活跃用户').locator('xpath=following::div[contains(@class, "text-2xl")][1]');
+    await expect(countElement).toBeVisible({ timeout: 10000 });
+    return await countElement.textContent() || '';
   }
 
   async getSystemMessagesCount(): Promise<string> {
-    return await this.systemMessagesCard.locator('xpath=following-sibling::div//div[contains(@class, "text-2xl")]').textContent() || '';
+    // 使用更可靠的定位器来获取系统消息统计数字
+    const countElement = this.page.locator('text=系统消息').locator('xpath=following::div[contains(@class, "text-2xl")][1]');
+    await expect(countElement).toBeVisible({ timeout: 10000 });
+    return await countElement.textContent() || '';
   }
 
   async logout() {