test: E2E 测试用例更新与新增

- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
This commit is contained in:
张翔
2026-05-06 14:17:51 +08:00
committed by zhangxiang
parent 9e635b1483
commit e8f51309e5
47 changed files with 1764 additions and 1226 deletions
@@ -1,106 +1,65 @@
import { Page, expect } from '@playwright/test';
import { Page, Locator, expect } from '@playwright/test';
export class FileManagementPage {
readonly page: Page;
readonly uploadButton;
readonly fileInput;
readonly table;
readonly deleteButton;
readonly downloadButton;
readonly searchInput;
readonly uploadButton: Locator;
readonly refreshButton: Locator;
readonly table: Locator;
readonly successMessage: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
this.uploadButton = page.locator('.el-upload--text').first();
this.fileInput = page.locator('input[type="file"]');
this.table = page.locator('.el-table');
this.deleteButton = page.getByRole('button', { name: '删除' });
this.downloadButton = page.getByRole('button', { name: '下载' });
this.searchInput = page.locator('.search-bar .el-input__inner');
this.uploadButton = page.getByRole('button', { name: '上传文件' });
this.refreshButton = page.getByRole('button', { name: '刷新' });
this.table = page.locator('.ant-table').first();
this.successMessage = page.locator('.ant-message-success');
this.errorMessage = page.locator('.ant-message-error');
}
async goto() {
try {
console.log('导航到文件管理页面...');
await this.page.goto('/files');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*files/);
console.log('文件管理页面加载完成');
} catch (error) {
await this.page.screenshot({ path: `test-results/file-management-error-${Date.now()}.png` });
console.error('导航到文件管理页面失败:', error);
throw new Error(`导航到文件管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
}
await this.page.goto('/files');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
await expect(this.page).toHaveURL(/.*files/);
}
async uploadFile(filePath: string) {
await this.uploadButton.waitFor({ state: 'visible', timeout: 10000 });
await this.uploadButton.click();
const fileInput = this.page.locator('input[type="file"]');
await fileInput.setInputFiles(filePath);
await this.page.waitForTimeout(1000);
await this.page.waitForTimeout(2000);
}
async deleteFile(fileName: string) {
const row = this.table.locator('tr').filter({ hasText: fileName }).first();
await row.locator('.el-button--danger').click();
const row = this.table.locator('tbody tr').filter({ hasText: fileName }).first();
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
await this.page.waitForTimeout(300);
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
const confirmButton = this.page.getByRole('button', { name: '确定' });
await confirmButton.click();
async previewFile(fileName: string) {
const row = this.table.locator('tbody tr').filter({ hasText: fileName }).first();
await row.getByRole('button', { name: '预览' }).click();
await this.page.waitForTimeout(500);
}
async closePreview() {
const modal = this.page.locator('.ant-modal').filter({ hasText: /预览/ });
await modal.getByRole('button', { name: '关闭' }).click();
}
async getTableRowCount(): Promise<number> {
return this.table.locator('tbody tr').count();
}
async containsText(text: string): Promise<boolean> {
return this.table.getByText(text).count() > 0;
}
async reload() {
await this.refreshButton.click();
await this.page.waitForLoadState('networkidle');
}
async downloadFile(fileName: string) {
const row = this.table.locator('tr').filter({ hasText: fileName }).first();
const downloadButton = row.locator('.el-button--primary').first();
await downloadButton.click();
}
async searchFile(keyword: string) {
await this.searchInput.fill(keyword);
await this.page.waitForTimeout(500);
}
async clearSearch() {
await this.searchInput.clear();
await this.page.waitForTimeout(500);
}
async verifyTableContains(text: string) {
await expect(this.table).toContainText(text);
}
async verifyTableNotContains(text: string) {
await expect(this.table).not.toContainText(text);
}
async getTableRowCount() {
const rows = await this.table.locator('.el-table__row').count();
return rows;
}
async clickUploadButton() {
await this.uploadButton.waitFor({ state: 'visible', timeout: 10000 });
await this.uploadButton.click();
}
async submitUpload() {
const confirmButton = this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.el-dialog .el-button--primary'));
await confirmButton.click();
}
async clickDeleteButton(rowNumber: number) {
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
await row.locator('.el-button--danger').click();
}
async clickDownloadButton(rowNumber: number) {
const row = this.table.locator(`tbody tr:nth-child(${rowNumber})`);
await row.locator('.el-button--primary').first().click();
}
}
}