import { Page, Locator, expect } from '@playwright/test'; export class FileManagementPage { readonly page: Page; readonly uploadButton: Locator; readonly refreshButton: Locator; readonly table: Locator; readonly successMessage: Locator; readonly errorMessage: Locator; constructor(page: Page) { this.page = page; 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() { 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.click(); const fileInput = this.page.locator('input[type="file"]'); await fileInput.setInputFiles(filePath); await this.page.waitForTimeout(2000); } async deleteFile(fileName: string) { 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); } 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 { return this.table.locator('tbody tr').count(); } async containsText(text: string): Promise { return this.table.getByText(text).count() > 0; } async reload() { await this.refreshButton.click(); await this.page.waitForLoadState('networkidle'); } }