From 00b0d3413b7667080e39dce620281fad334ff60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Tue, 7 Apr 2026 08:17:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(e2e):=20=E5=88=9B=E5=BB=BA=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=AE=8C=E6=95=B4=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现用户旅程测试: - 管理员登录 - 创建角色并分配权限 - 创建用户并分配角色 - 验证新用户登录 - 清理测试数据 采用 serial 模式确保测试顺序执行 --- .../journeys/admin-complete-workflow.spec.ts | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts diff --git a/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts b/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts new file mode 100644 index 0000000..a49b606 --- /dev/null +++ b/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts @@ -0,0 +1,137 @@ +import { test, expect } from '@playwright/test'; + +test.describe('管理员完整工作流', () => { + test.describe.configure({ mode: 'serial' }); + + const timestamp = Date.now(); + const roleName = `测试角色_${timestamp}`; + const roleKey = `test_role_${timestamp}`; + const username = `testuser_${timestamp}`; + + test('管理员登录', async ({ page }) => { + await test.step('访问登录页面', async () => { + await page.goto('/login'); + await expect(page).toHaveTitle(/登录/); + }); + + await test.step('输入管理员凭证', async () => { + await page.locator('input[placeholder*="用户名"]').fill('admin'); + await page.locator('input[placeholder*="密码"]').fill('admin123'); + }); + + await test.step('点击登录按钮', async () => { + await page.locator('button:has-text("登录")').click(); + }); + + await test.step('验证登录成功', async () => { + await page.waitForURL('**/dashboard', { timeout: 30000 }); + await expect(page).toHaveURL(/.*dashboard/); + }); + }); + + test('创建角色并分配权限', async ({ page }) => { + await test.step('导航到角色管理', async () => { + await page.goto('/dashboard'); + await page.locator('text=系统管理').click(); + await page.locator('text=角色管理').click(); + await expect(page).toHaveURL(/.*roles/); + }); + + await test.step('点击创建角色按钮', async () => { + await page.locator('button:has-text("新建")').click(); + }); + + await test.step('填写角色信息', async () => { + await page.locator('input[placeholder*="角色名称"]').fill(roleName); + await page.locator('input[placeholder*="角色标识"]').fill(roleKey); + await page.locator('input[placeholder*="排序"]').fill('1'); + await page.locator('textarea[placeholder*="备注"]').fill('测试角色'); + }); + + await test.step('提交表单', async () => { + await page.locator('button:has-text("确定")').click(); + await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); + }); + }); + + test('创建用户并分配角色', async ({ page }) => { + await test.step('导航到用户管理', async () => { + await page.goto('/dashboard'); + await page.locator('text=系统管理').click(); + await page.locator('text=用户管理').click(); + await expect(page).toHaveURL(/.*users/); + }); + + await test.step('点击创建用户按钮', async () => { + await page.locator('button:has-text("新建")').click(); + }); + + await test.step('填写用户信息', async () => { + await page.locator('input[placeholder*="用户名"]').fill(username); + await page.locator('input[placeholder*="昵称"]').fill(`测试用户${timestamp}`); + await page.locator('input[placeholder*="邮箱"]').fill(`test_${timestamp}@example.com`); + await page.locator('input[placeholder*="手机"]').fill('13800138000'); + await page.locator('input[placeholder*="密码"]').fill('Test@123'); + }); + + await test.step('提交表单', async () => { + await page.locator('button:has-text("确定")').click(); + await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); + }); + }); + + 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.waitForURL(/.*login/); + }); + + await test.step('新用户登录', async () => { + await page.goto('/login'); + await page.locator('input[placeholder*="用户名"]').fill(username); + await page.locator('input[placeholder*="密码"]').fill('Test@123'); + await page.locator('button:has-text("登录")').click(); + await page.waitForURL('**/dashboard', { timeout: 30000 }); + }); + + await test.step('验证用户信息', async () => { + const displayedUsername = await page.locator('.el-dropdown-link').textContent(); + expect(displayedUsername).toContain(username); + }); + }); + + 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.goto('/login'); + await page.locator('input[placeholder*="用户名"]').fill('admin'); + await page.locator('input[placeholder*="密码"]').fill('admin123'); + await page.locator('button:has-text("登录")').click(); + await page.waitForURL('**/dashboard'); + }); + + await test.step('删除测试用户', async () => { + await page.goto('/users'); + await page.locator('input[placeholder*="搜索"]').fill(username); + await page.locator('button:has-text("搜索")').click(); + await page.waitForTimeout(1000); + await page.locator('button:has-text("删除")').first().click(); + await page.locator('button:has-text("确定")').click(); + await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); + }); + + await test.step('删除测试角色', async () => { + await page.goto('/roles'); + await page.locator('input[placeholder*="搜索"]').fill(roleName); + await page.locator('button:has-text("搜索")').click(); + await page.waitForTimeout(1000); + await page.locator('button:has-text("删除")').first().click(); + await page.locator('button:has-text("确定")').click(); + await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 }); + }); + }); +});