119 lines
3.8 KiB
TypeScript
119 lines
3.8 KiB
TypeScript
import { Page, Locator, expect } from '@playwright/test';
|
|
|
|
export class CheckInManagementPage {
|
|
readonly page: Page;
|
|
readonly table: Locator;
|
|
readonly searchInput: Locator;
|
|
readonly searchButton: Locator;
|
|
readonly datePicker: Locator;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
this.table = page.locator('.el-table').first();
|
|
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
|
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
|
this.datePicker = page.locator('.el-date-editor').or(page.locator('.el-date-picker'));
|
|
}
|
|
|
|
async goto() {
|
|
try {
|
|
console.log('导航到数据统计页面(含签到统计)...');
|
|
await this.page.goto('/statistics');
|
|
|
|
await this.page.waitForURL('**/statistics', { timeout: 30000 });
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
|
// statistics page uses stat cards, not tables
|
|
const statCard = this.page.locator('.stat-card, .el-card, .summary-card');
|
|
await statCard.first().waitFor({ state: 'visible', timeout: 15000 });
|
|
|
|
await expect(this.page).toHaveURL(/.*statistics/);
|
|
|
|
console.log('数据统计页面加载完成(签到管理查看)');
|
|
} catch (error) {
|
|
await this.page.screenshot({ path: `test-results/checkin-management-error-${Date.now()}.png` });
|
|
console.error('导航到签到管理页面失败:', error);
|
|
throw new Error(`导航到签到管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
}
|
|
}
|
|
|
|
async waitForTableReady() {
|
|
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
|
|
|
await this.page.waitForFunction(
|
|
() => {
|
|
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
|
return rows.length > 0;
|
|
},
|
|
{ timeout: 5000 }
|
|
).catch(() => {
|
|
console.log('表格没有数据,继续执行');
|
|
});
|
|
}
|
|
|
|
async searchByDate(date: string) {
|
|
const dateInput = this.datePicker.locator('input').first();
|
|
if (await dateInput.count() > 0) {
|
|
await dateInput.click();
|
|
await this.page.waitForTimeout(300);
|
|
await dateInput.fill(date);
|
|
await this.page.waitForTimeout(300);
|
|
}
|
|
|
|
await this.searchButton.click();
|
|
await this.page.waitForTimeout(500);
|
|
}
|
|
|
|
async verifyTableHasRecords(): Promise<boolean> {
|
|
try {
|
|
await this.page.waitForFunction(
|
|
() => {
|
|
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
|
|
return rows.length > 0;
|
|
},
|
|
{ timeout: 5000 }
|
|
);
|
|
return true;
|
|
} catch {
|
|
console.log('签到表格没有记录');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async getRecordCount(): Promise<number> {
|
|
return await this.table.locator('tbody tr').count();
|
|
}
|
|
|
|
async containsText(text: string): Promise<boolean> {
|
|
return await this.table.getByText(text).count() > 0;
|
|
}
|
|
|
|
async verifySignInDataLoaded(): Promise<boolean> {
|
|
try {
|
|
const signInSection = this.page.locator('.stat-card, .el-card, .signin-section, .chart-container');
|
|
await signInSection.first().waitFor({ state: 'visible', timeout: 10000 });
|
|
console.log('签到数据区域已加载');
|
|
return true;
|
|
} catch {
|
|
console.log('签到数据区域未找到,尝试备选方式');
|
|
return await this.verifyTableHasRecords();
|
|
}
|
|
}
|
|
|
|
async getTotalSignIns(): Promise<string> {
|
|
const statCards = this.page.locator('.stat-card');
|
|
if (await statCards.count() > 0) {
|
|
return (await statCards.nth(0).textContent()) || '0';
|
|
}
|
|
return 'N/A';
|
|
}
|
|
|
|
async getSuccessSignIns(): Promise<string> {
|
|
const statCards = this.page.locator('.stat-card');
|
|
if (await statCards.count() > 1) {
|
|
return (await statCards.nth(1).textContent()) || '0';
|
|
}
|
|
return 'N/A';
|
|
}
|
|
}
|