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

- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
This commit is contained in:
张翔
2026-05-06 14:17:51 +08:00
parent 0b246b3e24
commit bd21e2d1f7
47 changed files with 1764 additions and 1226 deletions
@@ -1,88 +1,81 @@
import { Page, expect } from '@playwright/test';
import { Page, Locator, expect } from '@playwright/test';
export class NotificationPage {
readonly page: Page;
readonly table;
readonly addButton;
readonly saveButton;
readonly cancelButton;
readonly dialog;
readonly titleInput;
readonly contentInput;
readonly noticeTypeSelect;
readonly statusSelect;
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('.el-table');
this.addButton = page.getByRole('button', { name: '新增公告' });
this.saveButton = page.getByRole('button', { name: '确定' });
this.cancelButton = page.getByRole('button', { name: '取消' });
this.dialog = page.locator('.el-dialog');
this.titleInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告标题' });
this.contentInput = page.locator('.el-dialog').getByRole('textbox', { name: '公告内容' });
this.noticeTypeSelect = page.locator('.el-dialog').getByRole('combobox', { name: '公告类型' });
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
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() {
try {
console.log('导航到通知管理页面...');
await this.page.goto('/notice');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*notice/);
console.log('通知管理页面加载完成');
} catch (error) {
await this.page.screenshot({ path: `test-results/notification-error-${Date.now()}.png` });
console.error('导航到通知管理页面失败:', error);
throw new Error(`导航到通知管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
}
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) {
async addNotification(title: string, content: string, type?: string) {
await this.addButton.click();
await this.page.waitForTimeout(500);
await this.titleInput.fill(title);
await this.contentInput.fill(content);
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增通知|编辑通知/ });
await modal.locator('.ant-form-item').filter({ hasText: '标题' }).locator('input').fill(title);
await this.saveButton.click();
await this.page.waitForLoadState('networkidle');
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('tr').filter({ hasText: title }).first();
const editBtn = row.getByRole('button', { name: '编辑' });
await editBtn.click();
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);
await this.contentInput.clear();
await this.contentInput.fill(newContent);
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 this.saveButton.click();
await this.page.waitForLoadState('networkidle');
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async deleteNotification(title: string) {
const row = this.table.locator('tr').filter({ hasText: title }).first();
const deleteBtn = row.getByRole('button', { name: '删除' });
await deleteBtn.click();
await this.page.waitForTimeout(500);
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);
}
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
await confirmBtn.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 getTableRowCount() {
const rows = await this.table.locator('.el-table__row').count();
return rows;
}
async verifyTableContains(text: string) {
await expect(this.table).toContainText(text);
}
}