import { Page, Locator, expect } from '@playwright/test'; export class DashboardPage { readonly page: Page; readonly pageTitle: Locator; readonly activeUsersCard: Locator; readonly systemMessagesCard: Locator; readonly onlineUsersCard: Locator; readonly userManagementCard: Locator; readonly systemSettingsCard: Locator; constructor(page: Page) { this.page = page; this.pageTitle = page.getByRole('heading', { name: '仪表盘' }); this.activeUsersCard = page.getByText('活跃用户'); this.systemMessagesCard = page.getByText('系统消息'); this.onlineUsersCard = page.getByText('在线用户'); this.userManagementCard = page.getByText('用户管理'); this.systemSettingsCard = page.getByText('系统设置'); } async expectToBeVisible() { await expect(this.pageTitle).toBeVisible(); await expect(this.activeUsersCard).toBeVisible(); await expect(this.systemMessagesCard).toBeVisible(); await expect(this.onlineUsersCard).toBeVisible(); } async navigateToUserManagement() { await this.userManagementCard.click(); await this.page.waitForLoadState('networkidle'); } async navigateToSystemSettings() { await this.systemSettingsCard.click(); await this.page.waitForLoadState('networkidle'); } async getActiveUsersCount(): Promise { return await this.activeUsersCard.locator('xpath=following-sibling::div//div[contains(@class, "text-2xl")]').textContent() || ''; } async getSystemMessagesCount(): Promise { return await this.systemMessagesCard.locator('xpath=following-sibling::div//div[contains(@class, "text-2xl")]').textContent() || ''; } }