From 5938c70b6307aad3ec6f0e023eecea51976d0fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Tue, 7 Apr 2026 13:34:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(e2e):=20=E4=BC=98=E5=8C=96=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E5=AE=9A=E4=BD=8D=E5=99=A8=E5=92=8C?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 表单字段定位器过于复杂且不稳定 - 对话框打开/关闭缺少等待逻辑 - 菜单导航路径错误 - 页面加载等待时间不足 修复: - 简化表单字段定位器,使用索引定位 - 添加对话框状态等待(visible/hidden) - 修正菜单导航路径(系统配置 -> 参数配置/字典管理) - 增加页面加载等待和超时设置 - 统一菜单导航的等待策略 优势: - 提高测试稳定性 - 减少元素定位失败 - 确保页面完全加载后再操作 - 更清晰的测试代码结构 --- .../journeys/admin-complete-workflow.spec.ts | 33 ++++++++++++------- .../e2e/journeys/audit-workflow.spec.ts | 11 +++++-- .../journeys/system-config-workflow.spec.ts | 14 ++++++-- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts b/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts index 6fd0c1f..ab18a37 100644 --- a/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts +++ b/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts @@ -13,21 +13,26 @@ test.describe('管理员完整工作流', () => { await page.goto('/dashboard'); await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); + await page.waitForTimeout(500); await page.locator('text=角色管理').click(); - await expect(page).toHaveURL(/.*roles/); + await page.waitForLoadState('networkidle'); + await expect(page).toHaveURL(/.*roles/, { timeout: 10000 }); }); await test.step('点击创建角色按钮', async () => { await page.locator('button:has-text("新增角色")').click(); + await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); }); await test.step('填写角色信息', async () => { - await page.locator('.el-dialog').locator('text=角色名称').locator('..').locator('input').fill(roleName); - await page.locator('.el-dialog').locator('text=角色标识').locator('..').locator('input').fill(roleKey); + const dialog = page.locator('.el-dialog'); + await dialog.locator('input').first().fill(roleName); + await dialog.locator('input').nth(1).fill(roleKey); }); await test.step('提交表单', async () => { - await page.locator('button:has-text("确定")').click(); + await page.locator('.el-dialog button:has-text("确定")').click(); + await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); }); @@ -35,25 +40,31 @@ test.describe('管理员完整工作流', () => { test('创建用户并分配角色', async ({ page }) => { await test.step('导航到用户管理', async () => { await page.goto('/dashboard'); + await page.waitForLoadState('networkidle'); await page.locator('text=系统管理').click(); + await page.waitForTimeout(500); await page.locator('text=用户管理').click(); - await expect(page).toHaveURL(/.*users/); + await page.waitForLoadState('networkidle'); + await expect(page).toHaveURL(/.*users/, { timeout: 10000 }); }); await test.step('点击创建用户按钮', async () => { await page.locator('button:has-text("新增用户")').click(); + await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 }); }); await test.step('填写用户信息', async () => { - await page.locator('.el-dialog').locator('text=用户名').locator('..').locator('input').fill(username); - await page.locator('.el-dialog').locator('text=密码').locator('..').locator('input').fill('Test@123'); - await page.locator('.el-dialog').locator('text=昵称').locator('..').locator('input').fill(`测试用户${timestamp}`); - await page.locator('.el-dialog').locator('text=邮箱').locator('..').locator('input').fill(`test_${timestamp}@example.com`); - await page.locator('.el-dialog').locator('text=手机号').locator('..').locator('input').fill('13800138000'); + const dialog = page.locator('.el-dialog'); + await dialog.locator('input').first().fill(username); + await dialog.locator('input[type="password"]').fill('Test@123'); + await dialog.locator('input').nth(2).fill(`测试用户${timestamp}`); + await dialog.locator('input').nth(3).fill(`test_${timestamp}@example.com`); + await dialog.locator('input').nth(4).fill('13800138000'); }); await test.step('提交表单', async () => { - await page.locator('button:has-text("确定")').click(); + await page.locator('.el-dialog button:has-text("确定")').click(); + await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 }); await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); }); }); diff --git a/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts b/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts index b9a4553..d9c49f9 100644 --- a/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts +++ b/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts @@ -64,9 +64,16 @@ test.describe('审计工作流', () => { test('搜索和筛选日志', async ({ page }) => { await test.step('导航到操作日志', async () => { await page.goto('/dashboard'); - await page.locator('text=系统监控').click(); + await page.waitForLoadState('networkidle'); + + await page.locator('text=审计中心').click(); + await page.waitForTimeout(1000); + await page.locator('text=操作日志').click(); - await expect(page.locator('table')).toBeVisible(); + await page.waitForLoadState('networkidle'); + await page.waitForTimeout(1000); + + await expect(page.locator('table')).toBeVisible({ timeout: 10000 }); }); await test.step('按模块筛选', async () => { diff --git a/novalon-manage-web/e2e/journeys/system-config-workflow.spec.ts b/novalon-manage-web/e2e/journeys/system-config-workflow.spec.ts index 512593d..3a7591a 100644 --- a/novalon-manage-web/e2e/journeys/system-config-workflow.spec.ts +++ b/novalon-manage-web/e2e/journeys/system-config-workflow.spec.ts @@ -49,8 +49,12 @@ test.describe('系统配置工作流', () => { test('字典管理流程', async ({ page }) => { await test.step('导航到字典管理', async () => { await page.goto('/dashboard'); - await page.locator('text=系统管理').click(); + await page.waitForLoadState('networkidle'); + await page.locator('text=系统配置').click(); + await page.waitForTimeout(500); await page.locator('text=字典管理').click(); + await page.waitForLoadState('networkidle'); + await expect(page).toHaveURL(/.*dict/, { timeout: 10000 }); }); await test.step('查看字典列表', async () => { @@ -70,8 +74,12 @@ test.describe('系统配置工作流', () => { test('参数管理流程', async ({ page }) => { await test.step('导航到参数管理', async () => { await page.goto('/dashboard'); - await page.locator('text=系统管理').click(); - await page.locator('text=参数管理').click(); + await page.waitForLoadState('networkidle'); + await page.locator('text=系统配置').click(); + await page.waitForTimeout(500); + await page.locator('text=参数配置').click(); + await page.waitForLoadState('networkidle'); + await expect(page).toHaveURL(/.*sys\/config/, { timeout: 10000 }); }); await test.step('查看参数列表', async () => {