test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名 - 新增 UAT 测试套件与 journey 测试用例 - 优化测试辅助工具与数据工厂 - 更新 playwright 认证状态
This commit is contained in:
@@ -4,44 +4,24 @@ export class MenuManagementPage {
|
||||
readonly page: Page;
|
||||
readonly table: Locator;
|
||||
readonly createMenuButton: Locator;
|
||||
readonly searchInput: Locator;
|
||||
readonly searchButton: Locator;
|
||||
readonly refreshButton: Locator;
|
||||
readonly successMessage: Locator;
|
||||
readonly treeContainer: Locator;
|
||||
readonly expandAllButton: Locator;
|
||||
readonly collapseAllButton: Locator;
|
||||
readonly errorMessage: Locator;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
this.table = page.locator('.el-table').or(page.locator('.menu-table'));
|
||||
this.createMenuButton = page.getByRole('button', { name: '新增菜单' }).or(page.locator('button:has-text("新增菜单")'));
|
||||
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
||||
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
||||
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
||||
this.treeContainer = page.locator('.el-tree').or(page.locator('.menu-tree'));
|
||||
this.expandAllButton = page.getByRole('button', { name: '展开全部' }).or(page.locator('button:has-text("展开全部")'));
|
||||
this.collapseAllButton = page.getByRole('button', { name: '折叠全部' }).or(page.locator('button:has-text("折叠全部")'));
|
||||
this.table = page.locator('.ant-table').first();
|
||||
this.createMenuButton = 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('/menus');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.page.waitForSelector('.el-tree', { timeout: 10000 }).catch(() => {
|
||||
return this.page.waitForSelector('.el-table', { timeout: 5000 });
|
||||
});
|
||||
|
||||
await expect(this.page).toHaveURL(/.*menus/);
|
||||
|
||||
console.log('菜单管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/menu-management-error-${Date.now()}.png` });
|
||||
console.error('导航到菜单管理页面失败:', error);
|
||||
throw new Error(`导航到菜单管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
await this.page.goto('/menus');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 15000 }).catch(() => {});
|
||||
await expect(this.page).toHaveURL(/.*menus/);
|
||||
}
|
||||
|
||||
async clickCreateMenu() {
|
||||
@@ -49,120 +29,110 @@ export class MenuManagementPage {
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async clickAddChildMenu(parentMenuName: string) {
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: parentMenuName });
|
||||
await row.getByRole('button', { name: '新增子菜单' }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async fillMenuForm(menuData: {
|
||||
menuName: string;
|
||||
menuType?: string;
|
||||
name: string;
|
||||
type?: string;
|
||||
path?: string;
|
||||
icon?: string;
|
||||
component?: string;
|
||||
permission?: string;
|
||||
sort?: number;
|
||||
visible?: string;
|
||||
status?: string;
|
||||
visible?: boolean;
|
||||
}) {
|
||||
const dialog = this.page.locator('.el-dialog');
|
||||
|
||||
await dialog.locator('input').first().fill(menuData.menuName);
|
||||
|
||||
if (menuData.menuType) {
|
||||
const menuTypeSelect = dialog.locator('.el-select').first();
|
||||
await menuTypeSelect.click();
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '菜单名称' }).locator('input').fill(menuData.name);
|
||||
|
||||
if (menuData.type) {
|
||||
const typeSelect = modal.locator('.ant-form-item').filter({ hasText: '类型' }).locator('.ant-select');
|
||||
await typeSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
await this.page.getByRole('option', { name: menuData.menuType }).click();
|
||||
const typeMap: Record<string, string> = { directory: '目录', menu: '菜单', button: '按钮' };
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: typeMap[menuData.type] || menuData.type }).first().click();
|
||||
}
|
||||
|
||||
|
||||
if (menuData.path) {
|
||||
const pathInput = dialog.locator('input[placeholder*="路径"]');
|
||||
if (await pathInput.count() > 0) {
|
||||
await pathInput.fill(menuData.path);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '路径' }).locator('input').fill(menuData.path);
|
||||
}
|
||||
if (menuData.icon) {
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '图标' }).locator('input').fill(menuData.icon);
|
||||
}
|
||||
|
||||
if (menuData.component) {
|
||||
const componentInput = dialog.locator('input[placeholder*="组件"]');
|
||||
if (await componentInput.count() > 0) {
|
||||
await componentInput.fill(menuData.component);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '组件路径' }).locator('input').fill(menuData.component);
|
||||
}
|
||||
|
||||
if (menuData.permission) {
|
||||
const permissionInput = dialog.locator('input[placeholder*="权限"]');
|
||||
if (await permissionInput.count() > 0) {
|
||||
await permissionInput.fill(menuData.permission);
|
||||
}
|
||||
await modal.locator('.ant-form-item').filter({ hasText: '权限标识' }).locator('input').fill(menuData.permission);
|
||||
}
|
||||
|
||||
if (menuData.sort !== undefined) {
|
||||
const sortInput = dialog.locator('input[type="number"]');
|
||||
if (await sortInput.count() > 0) {
|
||||
await sortInput.fill(String(menuData.sort));
|
||||
}
|
||||
const sortInput = modal.locator('.ant-form-item').filter({ hasText: '排序' }).locator('.ant-input-number input');
|
||||
await sortInput.clear();
|
||||
await sortInput.fill(String(menuData.sort));
|
||||
}
|
||||
|
||||
if (menuData.visible) {
|
||||
const visibleRadio = dialog.locator(`input[value="${menuData.visible}"]`);
|
||||
if (await visibleRadio.count() > 0) {
|
||||
await visibleRadio.check();
|
||||
}
|
||||
}
|
||||
|
||||
if (menuData.status) {
|
||||
const statusRadio = dialog.locator(`input[value="${menuData.status}"]`);
|
||||
if (await statusRadio.count() > 0) {
|
||||
await statusRadio.check();
|
||||
}
|
||||
const statusSelect = modal.locator('.ant-form-item').filter({ hasText: '状态' }).locator('.ant-select');
|
||||
await statusSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const statusText = menuData.status === 'ACTIVE' ? '正常' : '停用';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: statusText }).first().click();
|
||||
}
|
||||
if (menuData.visible !== undefined) {
|
||||
const visibleSelect = modal.locator('.ant-form-item').filter({ hasText: '可见' }).locator('.ant-select');
|
||||
await visibleSelect.click();
|
||||
await this.page.waitForTimeout(300);
|
||||
const visibleText = menuData.visible ? '显示' : '隐藏';
|
||||
await this.page.locator('.ant-select-dropdown').locator('.ant-select-item').filter({ hasText: visibleText }).first().click();
|
||||
}
|
||||
}
|
||||
|
||||
async submitForm() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('button:has-text("确定")')).click();
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
await modal.getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async cancelForm() {
|
||||
const modal = this.page.locator('.ant-modal').filter({ hasText: /新增菜单|编辑菜单/ });
|
||||
await modal.getByRole('button', { name: /取\s*消/ }).click();
|
||||
}
|
||||
|
||||
async editMenu(menuName: string) {
|
||||
const menuRow = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await menuRow.getByRole('button', { name: '编辑' }).or(this.page.locator('.edit-button')).click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-edit') }).click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async deleteMenu(menuName: string) {
|
||||
const menuRow = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await menuRow.getByRole('button', { name: '删除' }).or(this.page.locator('.delete-button')).click();
|
||||
const row = this.table.locator('tbody tr').filter({ hasText: menuName });
|
||||
await row.locator('.ant-btn').filter({ has: this.page.locator('.anticon-delete') }).click();
|
||||
await this.page.waitForTimeout(300);
|
||||
}
|
||||
|
||||
async confirmDelete() {
|
||||
await this.page.getByRole('button', { name: '确定' }).or(this.page.locator('.confirm-dialog .confirm-button')).click();
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /确\s*定/ }).click();
|
||||
await this.page.waitForTimeout(1000);
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
await this.searchInput.fill(keyword);
|
||||
await this.searchButton.click();
|
||||
}
|
||||
|
||||
async expandAll() {
|
||||
await this.expandAllButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async collapseAll() {
|
||||
await this.collapseAllButton.click();
|
||||
await this.page.waitForTimeout(500);
|
||||
async cancelDelete() {
|
||||
await this.page.locator('.ant-popconfirm').getByRole('button', { name: /取\s*消/ }).click();
|
||||
}
|
||||
|
||||
async containsText(text: string): Promise<boolean> {
|
||||
return await this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async isSuccessMessageVisible(): Promise<boolean> {
|
||||
try {
|
||||
return await this.successMessage.isVisible({ timeout: 3000 });
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return this.table.getByText(text).count() > 0;
|
||||
}
|
||||
|
||||
async getMenuCount(): Promise<number> {
|
||||
return await this.table.locator('tbody tr').count();
|
||||
return this.table.locator('tbody tr').count();
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.page.reload();
|
||||
await this.refreshButton.click();
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user