import { Page, Locator, expect } from '@playwright/test'; export class NotificationPage { readonly page: Page; readonly table: Locator; readonly addButton: Locator; readonly refreshButton: Locator; readonly successMessage: Locator; readonly errorMessage: Locator; constructor(page: Page) { this.page = page; this.table = page.locator('.ant-table').first(); this.addButton = page.getByRole('button', { name: '新增通知' }); this.refreshButton = page.getByRole('button', { name: '刷新' }); this.successMessage = page.locator('.ant-message-success'); this.errorMessage = page.locator('.ant-message-error'); } async goto() { await this.page.goto('/notice'); await this.page.waitForLoadState('networkidle'); await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {}); await expect(this.page).toHaveURL(/.*notice/); } async addNotification(title: string, content: string, type?: string) { await this.addButton.click(); await this.page.waitForTimeout(500); const modal = this.page.locator('.ant-modal').filter({ hasText: /新增通知|编辑通知/ }); await modal.locator('.ant-form-item').filter({ hasText: '标题' }).locator('input').fill(title); if (type) { const typeSelect = modal.locator('.ant-form-item').filter({ hasText: '类型' }).locator('.ant-select'); await typeSelect.click(); await this.page.waitForTimeout(300); await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: type }).first().click(); } await modal.locator('.ant-form-item').filter({ hasText: '内容' }).locator('textarea').fill(content); await modal.getByRole('button', { name: /确\s*定/ }).click(); await this.page.waitForTimeout(1000); } async editNotification(title: string, newContent: string) { const row = this.table.locator('tbody tr').filter({ hasText: title }).first(); await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click(); await this.page.waitForTimeout(500); const modal = this.page.locator('.ant-modal').filter({ hasText: /新增通知|编辑通知/ }); const contentTextarea = modal.locator('.ant-form-item').filter({ hasText: '内容' }).locator('textarea'); await contentTextarea.clear(); await contentTextarea.fill(newContent); await modal.getByRole('button', { name: /确\s*定/ }).click(); await this.page.waitForTimeout(1000); } async deleteNotification(title: string) { const row = this.table.locator('tbody tr').filter({ hasText: title }).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 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'); } }