新增e2e测试脚本,修复部分问题

This commit was merged in pull request #51.
This commit is contained in:
2026-07-22 20:00:13 +08:00
parent 53d1ce6fb2
commit 4c07ec5455
105 changed files with 21700 additions and 318 deletions
@@ -0,0 +1,107 @@
import { Page, Locator, expect } from '@playwright/test';
export class StatisticsDashboardPage {
readonly page: Page;
readonly summaryCards: Locator;
readonly statCards: Locator;
constructor(page: Page) {
this.page = page;
this.summaryCards = page.locator('.el-card').or(page.locator('.statistics-card')).or(page.locator('.summary-card')).or(page.locator('.dashboard-card'));
this.statCards = page.locator('.stat-card').or(page.locator('.el-card')).or(page.locator('.summary-card'));
}
async goto() {
try {
console.log('导航到数据统计页面...');
await this.page.goto('/statistics');
await this.page.waitForLoadState('networkidle');
await expect(this.page).toHaveURL(/.*statistics/);
console.log('数据统计页面加载完成');
} catch (error) {
await this.page.screenshot({ path: `test-results/statistics-dashboard-error-${Date.now()}.png` });
console.error('导航到数据统计页面失败:', error);
throw new Error(`导航到数据统计页面失败: ${error instanceof Error ? error.message : String(error)}`);
}
}
async verifyStatisticsLoaded(): Promise<boolean> {
try {
await this.summaryCards.first().waitFor({ state: 'visible', timeout: 10000 });
const cardCount = await this.summaryCards.count();
console.log(`数据统计页面加载完成,找到 ${cardCount} 个统计卡片`);
return cardCount > 0;
} catch (error) {
console.log('统计卡片未找到,尝试备选选择器');
const altCards = this.page.locator('.statistics-container').or(this.page.locator('.dashboard-container'));
if (await altCards.count() > 0) {
await altCards.first().waitFor({ state: 'visible', timeout: 10000 });
return true;
}
return false;
}
}
async getSummaryCardCount(): Promise<number> {
return await this.summaryCards.count();
}
async getSummaryCardText(index: number): Promise<string | null> {
if (await this.summaryCards.count() > index) {
return await this.summaryCards.nth(index).textContent();
}
return null;
}
async verifyStatCardsLoaded(): Promise<boolean> {
try {
await this.statCards.first().waitFor({ state: 'visible', timeout: 15000 });
const cardCount = await this.statCards.count();
console.log(`统计卡片加载完成,共 ${cardCount}`);
return cardCount > 0;
} catch {
return false;
}
}
async getCardValue(index: number): Promise<string> {
const cards = this.statCards;
if (await cards.count() > index) {
return (await cards.nth(index).textContent()) || '0';
}
return '0';
}
async verifySectionCardsLoaded(): Promise<void> {
await this.page.waitForTimeout(500);
const allCards = this.page.locator('.el-card, .stat-card, .chart-container');
if (await allCards.count() > 0) {
console.log(`详细统计区域已加载,共 ${await allCards.count()} 个卡片/图表`);
}
}
async switchRange(range: string): Promise<void> {
const rangeBtn = this.page.locator('.el-radio-button').filter({ hasText: range }).or(this.page.locator('button').filter({ hasText: range }));
if (await rangeBtn.count() > 0) {
await rangeBtn.first().click();
await this.page.waitForTimeout(500);
}
}
async switchTab(tabName: string): Promise<void> {
const tab = this.page.locator('.el-tabs__item').filter({ hasText: tabName }).or(this.page.locator('.el-tab-pane')).filter({ hasText: tabName }).or(this.page.locator('[role="tab"]').filter({ hasText: tabName }));
if (await tab.count() > 0) {
await tab.first().click();
await this.page.waitForTimeout(800);
}
}
}