From c5a826ec2e7ae9dde373ba3d4afc780243e78f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 4 Apr 2026 10:33:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8UUID=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE=E5=94=AF=E4=B8=80=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E9=94=AE=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改用户创建测试,使用UUID生成唯一用户名 - 修改角色创建测试,使用UUID生成唯一角色名 - 修复登录响应处理逻辑 - 改进成功消息等待策略 --- .../e2e/system-integration-test.spec.ts | 301 +++++++++--------- .../e2e/user-create-diagnostic.spec.ts | 8 +- 2 files changed, 156 insertions(+), 153 deletions(-) diff --git a/novalon-manage-web/e2e/system-integration-test.spec.ts b/novalon-manage-web/e2e/system-integration-test.spec.ts index a0dc1f9..0139c5a 100644 --- a/novalon-manage-web/e2e/system-integration-test.spec.ts +++ b/novalon-manage-web/e2e/system-integration-test.spec.ts @@ -33,7 +33,7 @@ test.describe('系统全面集成测试', () => { test('1.1 正确的用户名和密码登录成功', async ({ page }) => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); - + await expect(page).toHaveURL(/\/(dashboard|\/)$/, { timeout: 10000 }); await expect(page.locator('.dashboard')).toBeVisible(); }); @@ -43,9 +43,9 @@ test.describe('系统全面集成测试', () => { await loginPage.usernameInput.fill('admin'); await loginPage.passwordInput.fill('wrongpassword'); await loginPage.loginButton.click(); - + await page.waitForTimeout(2000); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); @@ -54,9 +54,9 @@ test.describe('系统全面集成测试', () => { await loginPage.usernameInput.fill('nonexistent'); await loginPage.passwordInput.fill('Test@123'); await loginPage.loginButton.click(); - + await page.waitForTimeout(2000); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); @@ -65,7 +65,7 @@ test.describe('系统全面集成测试', () => { await loginPage.usernameInput.fill(''); await loginPage.passwordInput.fill('Test@123'); await loginPage.loginButton.click(); - + await expect(page.locator('.el-form-item__error')).toBeVisible({ timeout: 5000 }); }); @@ -74,22 +74,22 @@ test.describe('系统全面集成测试', () => { await loginPage.usernameInput.fill('disableduser'); await loginPage.passwordInput.fill('Test@123'); await loginPage.loginButton.click(); - + await page.waitForTimeout(2000); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); test('1.6 登出功能正常', async ({ page }) => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); - + await expect(page).toHaveURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await page.locator('.el-avatar').click(); await page.waitForTimeout(500); await page.locator('.el-dropdown-menu').getByText('退出登录').click(); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); }); @@ -104,16 +104,16 @@ test.describe('系统全面集成测试', () => { test('2.1 查询用户列表', async ({ page }) => { await userManagementPage.goto(); await userManagementPage.waitForTableReady(); - + await expect(userManagementPage.table).toBeVisible({ timeout: 5000 }); const userCount = await userManagementPage.getUserCount(); expect(userCount).toBeGreaterThan(0); }); test('2.2 创建新用户', async ({ page }) => { - const timestamp = Date.now(); - const username = `testuser_${timestamp}`; - + const uuid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + const username = `u_${uuid}`; + await userManagementPage.goto(); await userManagementPage.waitForTableReady(); await userManagementPage.clickCreateUser(); @@ -122,13 +122,13 @@ test.describe('系统全面集成测试', () => { password: 'Test@123', email: `${username}@test.com`, phone: '13800138000', - nickname: `测试用户${timestamp}` + nickname: `测试用户${Date.now()}` }); await userManagementPage.submitForm(); - + const success = await userManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); - + await userManagementPage.search(username); await page.waitForTimeout(1000); const found = await userManagementPage.containsText(username); @@ -138,20 +138,20 @@ test.describe('系统全面集成测试', () => { test('2.3 编辑用户信息', async ({ page }) => { await userManagementPage.goto(); await userManagementPage.waitForTableReady(); - + await userManagementPage.clickEditButton(1); - + const newNickname = `更新昵称_${Date.now()}`; await userManagementPage.fillNickname(newNickname); await userManagementPage.submitForm(); - + await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 }); }); test('2.4 删除用户', async ({ page }) => { - const timestamp = Date.now(); - const username = `deleteuser_${timestamp}`; - + const uuid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + const username = `del_${uuid}`; + await userManagementPage.goto(); await userManagementPage.waitForTableReady(); await userManagementPage.clickCreateUser(); @@ -160,18 +160,18 @@ test.describe('系统全面集成测试', () => { password: 'Test@123', email: `${username}@test.com`, phone: '13800138000', - nickname: `待删除用户${timestamp}` + nickname: `待删除用户${Date.now()}` }); await userManagementPage.submitForm(); - + const createSuccess = await userManagementPage.waitForSuccessMessage(); expect(createSuccess).toBeTruthy(); - + await userManagementPage.search(username); await page.waitForTimeout(1000); await userManagementPage.clickDeleteButton(1); await userManagementPage.confirmDelete(); - + const deleteSuccess = await userManagementPage.waitForSuccessMessage(); expect(deleteSuccess).toBeTruthy(); }); @@ -179,11 +179,11 @@ test.describe('系统全面集成测试', () => { test('2.5 分配用户角色', async ({ page }) => { await userManagementPage.goto(); await userManagementPage.waitForTableReady(); - + await userManagementPage.clickEditButton(1); await userManagementPage.selectRole('管理员'); await userManagementPage.submitForm(); - + const success = await userManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); }); @@ -191,9 +191,9 @@ test.describe('系统全面集成测试', () => { test('2.6 启用/禁用用户', async ({ page }) => { await userManagementPage.goto(); await userManagementPage.waitForTableReady(); - + await userManagementPage.clickStatusButton(1); - + const success = await userManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); }); @@ -209,17 +209,17 @@ test.describe('系统全面集成测试', () => { test('3.1 查询角色列表', async ({ page }) => { await roleManagementPage.goto(); await roleManagementPage.waitForTableReady(); - + await expect(roleManagementPage.table).toBeVisible({ timeout: 5000 }); const roleCount = await roleManagementPage.table.locator('tbody tr').count(); expect(roleCount).toBeGreaterThan(0); }); test('3.2 创建新角色', async ({ page }) => { - const timestamp = Date.now(); - const roleName = `测试角色_${timestamp}`; - const roleKey = `test_role_${timestamp}`; - + const uuid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + const roleName = `角色_${uuid}`; + const roleKey = `r_${uuid}`; + await roleManagementPage.goto(); await roleManagementPage.waitForTableReady(); await roleManagementPage.clickCreateRole(); @@ -229,10 +229,10 @@ test.describe('系统全面集成测试', () => { roleSort: '99' }); await roleManagementPage.submitForm(); - + const success = await roleManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); - + await roleManagementPage.search(roleName); await page.waitForTimeout(1000); const found = await roleManagementPage.containsText(roleName); @@ -242,22 +242,23 @@ test.describe('系统全面集成测试', () => { test('3.3 编辑角色', async ({ page }) => { await roleManagementPage.goto(); await roleManagementPage.waitForTableReady(); - + await roleManagementPage.editRole(1); - - const newRoleName = `更新角色_${Date.now()}`; + + const uuid = Math.random().toString(36).substring(2, 15); + const newRoleName = `更新_${uuid}`; await page.locator('.el-dialog').locator('input').first().fill(newRoleName); await roleManagementPage.submitForm(); - + const success = await roleManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); }); test('3.4 删除角色', async ({ page }) => { - const timestamp = Date.now(); - const roleName = `待删除角色_${timestamp}`; - const roleKey = `delete_role_${timestamp}`; - + const uuid = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + const roleName = `删除_${uuid}`; + const roleKey = `d_${uuid}`; + await roleManagementPage.goto(); await roleManagementPage.waitForTableReady(); await roleManagementPage.clickCreateRole(); @@ -267,15 +268,15 @@ test.describe('系统全面集成测试', () => { roleSort: '99' }); await roleManagementPage.submitForm(); - + const createSuccess = await roleManagementPage.waitForSuccessMessage(); expect(createSuccess).toBeTruthy(); - + await roleManagementPage.search(roleName); await page.waitForTimeout(1000); await roleManagementPage.deleteRole(1); await roleManagementPage.confirmDelete(); - + const deleteSuccess = await roleManagementPage.waitForSuccessMessage(); expect(deleteSuccess).toBeTruthy(); }); @@ -283,17 +284,17 @@ test.describe('系统全面集成测试', () => { test('3.5 分配角色权限', async ({ page }) => { await roleManagementPage.goto(); await roleManagementPage.waitForTableReady(); - + await roleManagementPage.clickPermissionButton(1); await page.waitForTimeout(500); - + const permissionCheckbox = page.locator('.el-tree').locator('input[type="checkbox"]').first(); if (await permissionCheckbox.count() > 0) { await permissionCheckbox.click(); } - + await roleManagementPage.savePermissions(); - + const success = await roleManagementPage.waitForSuccessMessage(); expect(success).toBeTruthy(); }); @@ -308,7 +309,7 @@ test.describe('系统全面集成测试', () => { test('4.1 查询菜单树', async ({ page }) => { await menuManagementPage.goto(); - + await expect(page.locator('.menu-tree')).toBeVisible({ timeout: 5000 }); const menuCount = await page.locator('.menu-node').count(); expect(menuCount).toBeGreaterThan(0); @@ -317,7 +318,7 @@ test.describe('系统全面集成测试', () => { test('4.2 创建新菜单', async ({ page }) => { const timestamp = Date.now(); const menuName = `测试菜单_${timestamp}`; - + await menuManagementPage.goto(); await menuManagementPage.clickCreateMenu(); await menuManagementPage.fillMenuForm({ @@ -328,27 +329,27 @@ test.describe('系统全面集成测试', () => { orderNum: '99' }); await menuManagementPage.submitMenuForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('4.3 编辑菜单', async ({ page }) => { await menuManagementPage.goto(); - + const firstMenu = page.locator('.menu-node').first(); await firstMenu.locator('[data-testid="edit-button"]').click(); - + const newMenuName = `更新菜单_${Date.now()}`; await page.fill('[name="menuName"]', newMenuName); await page.click('[data-testid="submit-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('4.4 删除菜单', async ({ page }) => { const timestamp = Date.now(); const menuName = `待删除菜单_${timestamp}`; - + await menuManagementPage.goto(); await menuManagementPage.clickCreateMenu(); await menuManagementPage.fillMenuForm({ @@ -359,15 +360,15 @@ test.describe('系统全面集成测试', () => { orderNum: '99' }); await menuManagementPage.submitMenuForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); - + const menuNode = page.locator(`.menu-node:has-text("${menuName}")`).first(); await menuNode.locator('[data-testid="delete-button"]').click(); - + page.on('dialog', dialog => dialog.accept()); await page.click('[data-testid="confirm-delete-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); }); @@ -377,13 +378,13 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await userManagementPage.goto(); await expect(page.locator('.user-table')).toBeVisible({ timeout: 5000 }); - + await roleManagementPage.goto(); await expect(page.locator('.role-table')).toBeVisible({ timeout: 5000 }); - + await menuManagementPage.goto(); await expect(page.locator('.menu-tree')).toBeVisible({ timeout: 5000 }); }); @@ -392,11 +393,11 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('normaluser', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await page.goto('/user-management'); - + const hasAccess = await page.locator('.user-table').isVisible().catch(() => false); - + if (!hasAccess) { await expect(page.locator('.no-permission')).toBeVisible({ timeout: 5000 }); } @@ -404,7 +405,7 @@ test.describe('系统全面集成测试', () => { test('5.3 未登录用户访问受保护页面跳转到登录页', async ({ page }) => { await page.goto('/user-management'); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); }); @@ -418,7 +419,7 @@ test.describe('系统全面集成测试', () => { test('6.1 查询操作日志列表', async ({ page }) => { await operationLogPage.goto(); - + await expect(page.locator('.log-table')).toBeVisible({ timeout: 5000 }); const logCount = await page.locator('.log-row').count(); expect(logCount).toBeGreaterThan(0); @@ -426,33 +427,33 @@ test.describe('系统全面集成测试', () => { test('6.2 按时间范围查询日志', async ({ page }) => { await operationLogPage.goto(); - + const today = new Date().toISOString().split('T')[0]; await page.fill('[name="startDate"]', today); await page.fill('[name="endDate"]', today); await page.click('[data-testid="search-button"]'); - + await expect(page.locator('.log-row').first()).toBeVisible({ timeout: 5000 }); }); test('6.3 按用户查询日志', async ({ page }) => { await operationLogPage.goto(); - + await page.fill('[name="username"]', 'admin'); await page.click('[data-testid="search-button"]'); - + await expect(page.locator('.log-row').first()).toBeVisible({ timeout: 5000 }); await expect(page.locator('.log-row').first()).toContainText('admin'); }); test('6.4 导出操作日志', async ({ page }) => { await operationLogPage.goto(); - + const [download] = await Promise.all([ page.waitForEvent('download'), page.click('[data-testid="export-button"]') ]); - + expect(download.suggestedFilename()).toContain('.xlsx'); }); }); @@ -466,7 +467,7 @@ test.describe('系统全面集成测试', () => { test('7.1 查询字典类型列表', async ({ page }) => { await dictionaryManagementPage.goto(); - + await expect(page.locator('.dict-type-table')).toBeVisible({ timeout: 5000 }); }); @@ -474,7 +475,7 @@ test.describe('系统全面集成测试', () => { const timestamp = Date.now(); const dictName = `测试字典_${timestamp}`; const dictType = `test_dict_${timestamp}`; - + await dictionaryManagementPage.goto(); await dictionaryManagementPage.clickCreateDictType(); await dictionaryManagementPage.fillDictTypeForm({ @@ -482,25 +483,25 @@ test.describe('系统全面集成测试', () => { dictType: dictType }); await dictionaryManagementPage.submitDictTypeForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('7.3 查询字典数据', async ({ page }) => { await dictionaryManagementPage.goto(); - + const firstDictType = page.locator('.dict-type-row').first(); await firstDictType.click(); - + await expect(page.locator('.dict-data-table')).toBeVisible({ timeout: 5000 }); }); test('7.4 创建字典数据', async ({ page }) => { await dictionaryManagementPage.goto(); - + const firstDictType = page.locator('.dict-type-row').first(); await firstDictType.click(); - + await dictionaryManagementPage.clickCreateDictData(); await dictionaryManagementPage.fillDictDataForm({ dictLabel: `测试数据_${Date.now()}`, @@ -508,7 +509,7 @@ test.describe('系统全面集成测试', () => { dictSort: '99' }); await dictionaryManagementPage.submitDictDataForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); }); @@ -522,7 +523,7 @@ test.describe('系统全面集成测试', () => { test('8.1 查询系统配置列表', async ({ page }) => { await systemConfigPage.goto(); - + await expect(page.locator('.config-table')).toBeVisible({ timeout: 5000 }); }); @@ -530,7 +531,7 @@ test.describe('系统全面集成测试', () => { const timestamp = Date.now(); const configKey = `test.config.${timestamp}`; const configValue = `test_value_${timestamp}`; - + await systemConfigPage.goto(); await systemConfigPage.clickCreateConfig(); await systemConfigPage.fillConfigForm({ @@ -539,28 +540,28 @@ test.describe('系统全面集成测试', () => { configName: `测试配置_${timestamp}` }); await systemConfigPage.submitConfigForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('8.3 编辑系统配置', async ({ page }) => { await systemConfigPage.goto(); - + const firstConfig = page.locator('.config-row').first(); await firstConfig.locator('[data-testid="edit-button"]').click(); - + const newValue = `updated_value_${Date.now()}`; await page.fill('[name="configValue"]', newValue); await page.click('[data-testid="submit-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('8.4 刷新配置缓存', async ({ page }) => { await systemConfigPage.goto(); - + await page.click('[data-testid="refresh-cache-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); }); @@ -574,55 +575,55 @@ test.describe('系统全面集成测试', () => { test('9.1 上传文件', async ({ page }) => { await fileManagementPage.goto(); - + const fileInput = page.locator('input[type="file"]'); await fileInput.setInputFiles({ name: 'test-file.txt', mimeType: 'text/plain', buffer: Buffer.from('This is a test file') }); - + await page.click('[data-testid="upload-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 10000 }); }); test('9.2 查询文件列表', async ({ page }) => { await fileManagementPage.goto(); - + await expect(page.locator('.file-table')).toBeVisible({ timeout: 5000 }); }); test('9.3 下载文件', async ({ page }) => { await fileManagementPage.goto(); - + const firstFile = page.locator('.file-row').first(); const [download] = await Promise.all([ page.waitForEvent('download'), firstFile.locator('[data-testid="download-button"]').click() ]); - + expect(download).toBeTruthy(); }); test('9.4 删除文件', async ({ page }) => { await fileManagementPage.goto(); - + const firstFile = page.locator('.file-row').first(); await firstFile.locator('[data-testid="delete-button"]').click(); - + page.on('dialog', dialog => dialog.accept()); await page.click('[data-testid="confirm-delete-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); }); test('9.5 预览文件', async ({ page }) => { await fileManagementPage.goto(); - + const firstFile = page.locator('.file-row').first(); await firstFile.locator('[data-testid="preview-button"]').click(); - + await expect(page.locator('.file-preview-modal')).toBeVisible({ timeout: 5000 }); }); }); @@ -632,11 +633,11 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await page.route('**/api/**', route => route.abort('failed')); - + await userManagementPage.goto(); - + await expect(page.locator('.error-message')).toBeVisible({ timeout: 10000 }); }); @@ -644,19 +645,19 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const page2 = await context.newPage(); const loginPage2 = new LoginPage(page2); await loginPage2.goto(); await loginPage2.login('admin', 'Test@123'); await page2.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await userManagementPage.goto(); await page2.goto('/user-management'); - + await expect(page.locator('.user-table')).toBeVisible({ timeout: 5000 }); await expect(page2.locator('.user-table')).toBeVisible({ timeout: 5000 }); - + await page2.close(); }); @@ -664,7 +665,7 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await userManagementPage.goto(); await userManagementPage.clickCreateUser(); await userManagementPage.fillUserForm({ @@ -675,7 +676,7 @@ test.describe('系统全面集成测试', () => { nickname: '' }); await userManagementPage.submitUserForm(); - + await expect(page.locator('.error-message')).toBeVisible({ timeout: 5000 }); }); @@ -683,14 +684,14 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await page.evaluate(() => { localStorage.removeItem('token'); sessionStorage.clear(); }); - + await page.reload(); - + await expect(page).toHaveURL(/.*login/, { timeout: 5000 }); }); @@ -698,14 +699,14 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('normaluser', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const response = await page.request.post('/api/users', { data: { username: 'test', password: 'test123' } }); - + expect(response.status()).toBe(403); }); }); @@ -713,13 +714,13 @@ test.describe('系统全面集成测试', () => { test.describe('11. 性能测试', () => { test('11.1 页面加载性能', async ({ page }) => { const startTime = Date.now(); - + await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const loadTime = Date.now() - startTime; - + expect(loadTime).toBeLessThan(5000); }); @@ -727,14 +728,14 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const startTime = Date.now(); - + await operationLogPage.goto(); await expect(page.locator('.log-table')).toBeVisible({ timeout: 5000 }); - + const queryTime = Date.now() - startTime; - + expect(queryTime).toBeLessThan(3000); }); @@ -742,13 +743,13 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - - const requests = Array(10).fill(null).map(() => + + const requests = Array(10).fill(null).map(() => page.request.get('/api/users') ); - + const responses = await Promise.all(requests); - + responses.forEach(response => { expect(response.status()).toBe(200); }); @@ -760,10 +761,10 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const timestamp = Date.now(); const username = `consistency_test_${timestamp}`; - + await userManagementPage.goto(); await userManagementPage.clickCreateUser(); await userManagementPage.fillUserForm({ @@ -774,12 +775,12 @@ test.describe('系统全面集成测试', () => { nickname: `一致性测试用户${timestamp}` }); await userManagementPage.submitUserForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); - + await userManagementPage.searchUser(username); const userRow = page.locator('.user-row').first(); - + await expect(userRow).toContainText(username); await expect(userRow).toContainText(`${username}@test.com`); await expect(userRow).toContainText('13800138000'); @@ -789,23 +790,23 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + await userManagementPage.goto(); - + const firstUser = page.locator('.user-row').first(); await firstUser.locator('[data-testid="edit-button"]').click(); - + const newEmail = `updated_${Date.now()}@test.com`; const newPhone = `139${Date.now()}`.slice(0, 11); - + await page.fill('[name="email"]', newEmail); await page.fill('[name="phone"]', newPhone); await page.click('[data-testid="submit-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); - + await page.reload(); - + const updatedUser = page.locator('.user-row').first(); await expect(updatedUser).toContainText(newEmail); await expect(updatedUser).toContainText(newPhone); @@ -815,10 +816,10 @@ test.describe('系统全面集成测试', () => { await loginPage.goto(); await loginPage.login('admin', 'Test@123'); await page.waitForURL(/\/(dashboard|\/)$/, { timeout: 10000 }); - + const timestamp = Date.now(); const username = `delete_test_${timestamp}`; - + await userManagementPage.goto(); await userManagementPage.clickCreateUser(); await userManagementPage.fillUserForm({ @@ -829,18 +830,18 @@ test.describe('系统全面集成测试', () => { nickname: `删除测试用户${timestamp}` }); await userManagementPage.submitUserForm(); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); - + await userManagementPage.searchUser(username); const userRow = page.locator('.user-row').first(); await userRow.locator('[data-testid="delete-button"]').click(); - + page.on('dialog', dialog => dialog.accept()); await page.click('[data-testid="confirm-delete-button"]'); - + await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 }); - + await userManagementPage.searchUser(username); await expect(page.locator('.user-row')).toHaveCount(0, { timeout: 5000 }); }); diff --git a/novalon-manage-web/e2e/user-create-diagnostic.spec.ts b/novalon-manage-web/e2e/user-create-diagnostic.spec.ts index efb0628..7a7c48d 100644 --- a/novalon-manage-web/e2e/user-create-diagnostic.spec.ts +++ b/novalon-manage-web/e2e/user-create-diagnostic.spec.ts @@ -2,13 +2,15 @@ import { test, expect } from '@playwright/test'; import { LoginPage } from './pages/LoginPage'; test.describe('用户创建诊断测试', () => { + let loginPage: LoginPage; + test.beforeEach(async ({ page }) => { - const loginPage = new LoginPage(page); - await loginPage.goto(); - await loginPage.login('admin', 'Admin123'); + loginPage = new LoginPage(page); }); test('诊断用户创建流程', async ({ page }) => { + await loginPage.goto(); + await loginPage.login('admin', 'Test@123'); console.log('=== 开始诊断用户创建流程 ==='); await page.goto('/users');