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
@@ -2,95 +2,109 @@ import { Page, Locator, expect } from '@playwright/test';
export class DictionaryManagementPage {
readonly page: Page;
readonly table: Locator;
readonly createDictButton: Locator;
readonly saveButton: Locator;
readonly dialog: Locator;
readonly dictNameInput: Locator;
readonly dictTypeInput: Locator;
readonly statusSelect: Locator;
readonly remarkInput: Locator;
readonly typeTable: Locator;
readonly dataTable: Locator;
readonly addTypeButton: Locator;
readonly addDataButton: Locator;
readonly successMessage: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
this.table = page.locator('.el-table');
this.createDictButton = page.getByRole('button', { name: '新增字典' });
this.saveButton = page.getByRole('button', { name: '确定' });
this.dialog = page.locator('.el-dialog');
this.dictNameInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典名称' });
this.dictTypeInput = page.locator('.el-dialog').getByRole('textbox', { name: '字典类型' });
this.statusSelect = page.locator('.el-dialog').getByRole('combobox', { name: '状态' });
this.remarkInput = page.locator('.el-dialog').getByRole('textbox', { name: '备注' });
this.typeTable = page.locator('.ant-card').filter({ hasText: '字典类型' }).locator('.ant-table').first();
this.dataTable = page.locator('.ant-card').filter({ hasText: '字典数据' }).locator('.ant-table').first();
this.addTypeButton = page.locator('.ant-card').filter({ hasText: '字典类型' }).getByRole('button', { name: '新增' });
this.addDataButton = page.locator('.ant-card').filter({ hasText: '字典数据' }).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('/dict');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*dict/);
console.log('字典管理页面加载完成');
} catch (error) {
await this.page.screenshot({ path: `test-results/dict-management-error-${Date.now()}.png` });
console.error('导航到字典管理页面失败:', error);
throw new Error(`导航到字典管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
}
await this.page.goto('/dict');
await this.page.waitForLoadState('networkidle');
await this.typeTable.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
await expect(this.page).toHaveURL(/.*dict/);
}
async createDict(dictName: string, dictType: string, status: string = '0', remark?: string) {
await this.createDictButton.click();
async createDictType(dictName: string, dictType: string, status: number = 1, remark?: string) {
await this.addTypeButton.click();
await this.page.waitForTimeout(500);
await this.dictNameInput.fill(dictName);
await this.dictTypeInput.fill(dictType);
if (status) {
await this.statusSelect.click();
await this.page.waitForTimeout(300);
await this.page.getByRole('option', { name: status === '0' ? '正常' : '停用' }).click();
}
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
await modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input').fill(dictName);
await modal.locator('.ant-form-item').filter({ hasText: '字典类型' }).locator('input').fill(dictType);
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
await statusSelect.click();
await this.page.waitForTimeout(300);
const statusText = status === 1 ? '正常' : '停用';
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
if (remark) {
await this.remarkInput.fill(remark);
await modal.locator('.ant-form-item').filter({ hasText: '备注' }).locator('textarea').fill(remark);
}
await this.saveButton.click();
await this.page.waitForLoadState('networkidle');
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async editDict(dictName: string, newDictName: string) {
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
const editBtn = row.getByRole('button', { name: '编辑' });
await editBtn.click();
async editDictType(dictName: string, newDictName: string) {
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).first();
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
await this.page.waitForTimeout(500);
await this.dictNameInput.clear();
await this.dictNameInput.fill(newDictName);
await this.saveButton.click();
await this.page.waitForLoadState('networkidle');
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增字典类型|编辑字典类型/ });
const nameInput = modal.locator('.ant-form-item').filter({ hasText: '字典名称' }).locator('input');
await nameInput.clear();
await nameInput.fill(newDictName);
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async deleteDict(dictName: string) {
const row = this.table.locator('tr').filter({ hasText: dictName }).first();
const deleteBtn = row.getByRole('button', { name: '删除' });
await deleteBtn.click();
async deleteDictType(dictName: string) {
const row = this.typeTable.locator('tbody tr').filter({ hasText: dictName }).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 selectDictType(dictType: string) {
const link = this.typeTable.locator('a').filter({ hasText: dictType });
await link.click();
await this.page.waitForTimeout(500);
const confirmBtn = this.page.locator('.el-message-box').getByRole('button', { name: '确定' });
await confirmBtn.click();
await this.page.waitForLoadState('networkidle');
}
async getDictCount() {
const rows = await this.table.locator('.el-table__row').count();
return rows;
async createDictData(dictLabel: string, dictValue: string, sort: number = 0, status: number = 1) {
await this.addDataButton.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(dictLabel);
await modal.locator('.ant-form-item').filter({ hasText: '字典值' }).locator('input').fill(dictValue);
if (sort > 0) {
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
await sortInput.clear();
await sortInput.fill(String(sort));
}
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
await statusSelect.click();
await this.page.waitForTimeout(300);
const statusText = status === 1 ? '正常' : '停用';
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
await modal.getByRole('button', { name: /确\s*定/ }).click();
await this.page.waitForTimeout(1000);
}
async containsText(text: string): Promise<boolean> {
return await this.table.getByText(text).count() > 0;
async typeContainsText(text: string): Promise<boolean> {
return this.typeTable.getByText(text).count() > 0;
}
async dataContainsText(text: string): Promise<boolean> {
return this.dataTable.getByText(text).count() > 0;
}
}