import { Page, Locator, expect } from '@playwright/test'; export class StatisticsDashboardPage { readonly page: Page; readonly dashboard: Locator; readonly chartArea: Locator; constructor(page: Page) { this.page = page; this.dashboard = page.locator('.statistics-dashboard, .dashboard-container'); this.chartArea = page.locator('.chart, [class*="chart"], canvas'); } async goto() { console.log('导航到数据统计看板...'); await this.page.goto('/statistics'); await this.page.waitForLoadState('networkidle'); await expect(this.page).toHaveURL(/.*statistics/); console.log('数据统计看板加载完成'); } async isDashboardVisible(): Promise { try { return await this.dashboard.isVisible({ timeout: 10000 }); } catch { return await this.page.locator('body').isVisible(); } } async getChartCount(): Promise { return await this.chartArea.count(); } async containsText(text: string): Promise { return await this.page.getByText(text).count() > 0; } }