Files
novalon-manage-system/novalon-manage-web/e2e/pages/NotificationPage.ts
T
张翔 e8f51309e5 test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
2026-05-06 19:43:39 +08:00

82 lines
3.2 KiB
TypeScript

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<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');
}
}