From b835c27750538d82970b4e8e1307f46b5cab40f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Tue, 7 Apr 2026 13:42:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(e2e):=20=E4=BF=AE=E5=A4=8Dstrict=20mode=20v?= =?UTF-8?q?iolation=E5=92=8C=E7=99=BB=E5=87=BA=E6=8C=89=E9=92=AE=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - '操作日志'文本匹配到2个元素(菜单项和页面标题) - table定位器匹配到2个元素(header和body) - .el-dropdown-link元素找不到导致登出失败 修复: - 使用menuitem角色定位菜单项 - 使用.el-table类定位表格容器 - 使用button:has-text('admin')定位用户下拉菜单 - 添加页面加载等待和超时设置 优势: - 避免strict mode violation错误 - 提高定位器精确性 - 确保登出功能正常工作 --- .../journeys/admin-complete-workflow.spec.ts | 20 +++++++++++++++---- .../e2e/journeys/audit-workflow.spec.ts | 14 ++++++------- novalon-manage-web/playwright/.auth/user.json | 2 +- 3 files changed, 24 insertions(+), 12 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 ab18a37..2336a67 100644 --- a/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts +++ b/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts @@ -72,9 +72,14 @@ test.describe('管理员完整工作流', () => { test('验证新用户登录', async ({ page }) => { await test.step('管理员登出', async () => { await page.goto('/dashboard'); - await page.locator('.el-dropdown-link').click(); + await page.waitForLoadState('networkidle'); + + const dropdownButton = page.locator('button:has-text("admin")').first(); + await dropdownButton.click(); + await page.waitForTimeout(500); + await page.locator('text=退出登录').click(); - await page.waitForURL(/.*login/); + await page.waitForURL(/.*login/, { timeout: 10000 }); }); await test.step('新用户登录', async () => { @@ -94,8 +99,15 @@ test.describe('管理员完整工作流', () => { test('清理测试数据', async ({ page }) => { await test.step('管理员重新登录', async () => { await page.goto('/dashboard'); - await page.locator('.el-dropdown-link').click(); - await page.locator('text=退出登录').click(); + await page.waitForLoadState('networkidle'); + + const dropdownButton = page.locator('button:has-text("admin")').first(); + if (await dropdownButton.isVisible()) { + await dropdownButton.click(); + await page.waitForTimeout(500); + await page.locator('text=退出登录').click(); + } + await page.goto('/login'); await page.locator('input[placeholder*="用户名"]').fill('admin'); await page.locator('input[placeholder*="密码"]').fill('admin123'); diff --git a/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts b/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts index d9c49f9..c16825c 100644 --- a/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts +++ b/novalon-manage-web/e2e/journeys/audit-workflow.spec.ts @@ -24,12 +24,12 @@ test.describe('审计工作流', () => { await page.locator('text=审计中心').click(); await page.waitForTimeout(1000); - await page.locator('text=操作日志').click(); + await page.locator('menuitem:has-text("操作日志")').click(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); await expect(page).toHaveURL(/.*oplog/, { timeout: 10000 }); - await expect(page.locator('table')).toBeVisible({ timeout: 10000 }); + await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); await test.step('验证操作日志记录', async () => { @@ -47,7 +47,7 @@ test.describe('审计工作流', () => { await page.locator('text=审计中心').click(); await page.waitForTimeout(1000); - await page.locator('text=登录日志').click(); + await page.locator('menuitem:has-text("登录日志")').click(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); @@ -55,8 +55,8 @@ test.describe('审计工作流', () => { }); await test.step('验证登录日志显示', async () => { - await expect(page.locator('table')).toBeVisible(); - const logContent = await page.locator('table').textContent(); + await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); + const logContent = await page.locator('.el-table').textContent(); expect(logContent).toContain('admin'); }); }); @@ -69,11 +69,11 @@ test.describe('审计工作流', () => { await page.locator('text=审计中心').click(); await page.waitForTimeout(1000); - await page.locator('text=操作日志').click(); + await page.locator('menuitem:has-text("操作日志")').click(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(1000); - await expect(page.locator('table')).toBeVisible({ timeout: 10000 }); + await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 }); }); await test.step('按模块筛选', async () => { diff --git a/novalon-manage-web/playwright/.auth/user.json b/novalon-manage-web/playwright/.auth/user.json index 37ad976..df267e7 100644 --- a/novalon-manage-web/playwright/.auth/user.json +++ b/novalon-manage-web/playwright/.auth/user.json @@ -14,7 +14,7 @@ }, { "name": "token", - "value": "eyJhbGciOiJIUzM4NCJ9.eyJyb2xlcyI6W10sInVzZXJJZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInN1YiI6ImFkbWluIiwiaWF0IjoxNzc1NTM4NzgxLCJleHAiOjE3NzU2MjUxODF9.-YWMX8Fdyt8-W0rppNP5QT6t2KI2HMj95LTijW209EBAav4u1lNuZZvBLUp0mbhT" + "value": "eyJhbGciOiJIUzM4NCJ9.eyJyb2xlcyI6W10sInVzZXJJZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInN1YiI6ImFkbWluIiwiaWF0IjoxNzc1NTQwMTQ4LCJleHAiOjE3NzU2MjY1NDh9.4i6qWxQjh--zr9CD8HDtM2ewxuEd4dITICiclx9ukcbFGWwu9WhDfhTSC4vWycAQ" } ] }