refactor(e2e): 删除 UAT 阶段性测试

- 删除 comprehensive-uat.spec.ts
- 删除 uat-phase1 到 uat-phase8 所有文件

原因:这些测试与 comprehensive-e2e.spec.ts 重复,将被用户旅程测试替代
This commit is contained in:
张翔
2026-04-07 08:16:01 +08:00
parent 477e428e95
commit 356de2e5e2
9 changed files with 0 additions and 2028 deletions
@@ -1,833 +0,0 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
import { DashboardPage } from './pages/DashboardPage';
import { UserManagementPage } from './pages/UserManagementPage';
import { RoleManagementPage } from './pages/RoleManagementPage';
import { MenuManagementPage } from './pages/MenuManagementPage';
import { SystemConfigPage } from './pages/SystemConfigPage';
import { FileManagementPage } from './pages/FileManagementPage';
import { OperationLogPage } from './pages/OperationLogPage';
import { NotificationPage } from './pages/NotificationPage';
import { DictionaryManagementPage } from './pages/DictionaryManagementPage';
import { TestDataCleanup } from './utils/TestDataCleanup';
test.describe('UAT用户验收测试', () => {
let testDataCleanup: TestDataCleanup;
test.beforeEach(async ({ page }) => {
testDataCleanup = new TestDataCleanup(page);
});
test.afterEach(async ({ page }) => {
await testDataCleanup.cleanupAll();
});
test('UAT-001: 用户注册与首次登录场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const userManagementPage = new UserManagementPage(page);
const timestamp = Date.now();
await test.step('1. 管理员登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 创建新用户账号', async () => {
await dashboardPage.navigateToUserManagement();
await userManagementPage.clickCreateUser();
const userData = {
username: `newuser_${timestamp}`,
nickname: `新员工${timestamp}`,
email: `newuser_${timestamp}@example.com`,
phone: '13800138000',
password: 'Test123!@#',
confirmPassword: 'Test123!@#',
};
await userManagementPage.fillUserForm(userData);
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
testDataCleanup.trackUser(userData.username);
});
await test.step('3. 设置初始密码', async () => {
await userManagementPage.editUser(1);
const dialog = page.locator('.el-dialog');
const passwordInput = dialog.locator('.el-form-item').filter({ hasText: '密码' }).locator('input[type="password"]');
await passwordInput.fill('NewPass123!@#');
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
});
await test.step('4. 分配基本角色', async () => {
await userManagementPage.editUser(1);
await page.click('.role-select');
await page.click('option:has-text("普通用户")');
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
});
await test.step('5. 新用户使用初始密码登录', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login(`newuser_${timestamp}`, 'NewPass123!@#');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('6. 验证密码修改提示', async () => {
await expect(page.locator('.password-change-notice')).toBeVisible();
});
await test.step('7. 修改密码', async () => {
await dashboardPage.navigateToProfile();
await page.fill('input[name="oldPassword"]', 'NewPass123!@#');
await page.fill('input[name="newPassword"]', 'FinalPass123!@#');
await page.fill('input[name="confirmPassword"]', 'FinalPass123!@#');
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('8. 验证登录成功', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login(`newuser_${timestamp}`, 'FinalPass123!@#');
await expect(page).toHaveURL(/.*dashboard/);
const username = await dashboardPage.getUsername();
expect(username).toContain(`newuser_${timestamp}`);
});
await test.step('9. 查看欢迎信息', async () => {
await expect(page.locator('.welcome-message')).toBeVisible();
await expect(page.locator('.welcome-message')).toContainText('欢迎');
});
await test.step('10. 查看系统通知', async () => {
await dashboardPage.navigateToNotification();
await expect(page.locator('.notification-list')).toBeVisible();
});
});
test('UAT-002: 用户信息管理场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const userManagementPage = new UserManagementPage(page);
const timestamp = Date.now();
await test.step('1. 用户登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 导航到个人信息页面', async () => {
await dashboardPage.navigateToProfile();
await expect(page.locator('.profile-form')).toBeVisible();
});
await test.step('3. 查看当前信息', async () => {
const currentUsername = await page.locator('input[name="username"]').inputValue();
expect(currentUsername).toBe('admin');
});
await test.step('4. 修改昵称', async () => {
await page.fill('input[name="nickname"]', `管理员_${timestamp}`);
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('5. 修改邮箱', async () => {
await page.fill('input[name="email"]', `admin_${timestamp}@example.com`);
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('6. 修改手机号', async () => {
await page.fill('input[name="phone"]', '13900139000');
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('7. 上传头像', async () => {
const fileInput = page.locator('input[type="file"]');
await fileInput.setInputFiles('./e2e/fixtures/test-file.txt');
await page.click('button[type="submit"]');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('8. 保存修改', async () => {
await page.click('button:has-text("保存")');
await expect(page.locator('.success-message')).toBeVisible();
});
await test.step('9. 验证信息更新', async () => {
await page.reload();
await expect(page.locator('input[name="nickname"]')).toHaveValue(`管理员_${timestamp}`);
});
await test.step('10. 查看操作日志', async () => {
await dashboardPage.navigateToOperationLog();
await expect(page.locator('table')).toContainText('个人信息');
});
});
test('UAT-003: 角色权限分配场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const roleManagementPage = new RoleManagementPage(page);
const userManagementPage = new UserManagementPage(page);
const timestamp = Date.now();
await test.step('1. 管理员登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 创建新角色', async () => {
await dashboardPage.navigateToRoleManagement();
await roleManagementPage.clickCreateRole();
const roleData = {
roleName: `业务角色_${timestamp}`,
roleKey: `business_role_${timestamp}`,
roleSort: '1',
status: '1',
remark: `业务操作角色_${timestamp}`,
};
await roleManagementPage.fillRoleForm(roleData);
await roleManagementPage.submitForm();
await expect(roleManagementPage.successMessage).toBeVisible();
testDataCleanup.trackRole(roleData.roleKey);
});
await test.step('3. 配置角色基本信息', async () => {
await roleManagementPage.editRole(1);
await page.fill('input[name="remark"]', `更新备注_${timestamp}`);
await roleManagementPage.submitForm();
await expect(roleManagementPage.successMessage).toBeVisible();
});
await test.step('4. 分配菜单权限', async () => {
await roleManagementPage.openPermissionDialog(1);
await roleManagementPage.selectPermission('system:user:view');
await roleManagementPage.selectPermission('system:user:add');
await roleManagementPage.selectPermission('system:user:edit');
await roleManagementPage.submitPermissions();
await expect(roleManagementPage.successMessage).toBeVisible();
});
await test.step('5. 分配API权限', async () => {
await roleManagementPage.openPermissionDialog(1);
await roleManagementPage.selectPermission('api:user:list');
await roleManagementPage.selectPermission('api:user:create');
await roleManagementPage.submitPermissions();
await expect(roleManagementPage.successMessage).toBeVisible();
});
await test.step('6. 保存角色配置', async () => {
await roleManagementPage.saveRole();
await expect(roleManagementPage.successMessage).toBeVisible();
});
await test.step('7. 为用户分配角色', async () => {
await dashboardPage.navigateToUserManagement();
await userManagementPage.editUser(1);
await page.click('.role-select');
await page.click('option:has-text("业务角色")');
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
});
await test.step('8. 用户重新登录', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('9. 验证权限生效', async () => {
await dashboardPage.navigateToUserManagement();
await expect(page).toHaveURL(/.*users/);
await expect(page.locator('button:has-text("新增")')).toBeVisible();
});
await test.step('10. 查看权限日志', async () => {
await dashboardPage.navigateToOperationLog();
await expect(page.locator('table')).toContainText('权限');
});
});
test('UAT-004: 菜单管理场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const menuManagementPage = new MenuManagementPage(page);
const roleManagementPage = new RoleManagementPage(page);
const timestamp = Date.now();
await test.step('1. 管理员登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 创建父级菜单', async () => {
await dashboardPage.navigateToMenuManagement();
await menuManagementPage.clickCreateMenu();
const menuData = {
menuName: `业务菜单_${timestamp}`,
parentId: '0',
orderNum: '1',
menuType: 'M',
component: `business_${timestamp}`,
perms: `business:view_${timestamp}`,
status: '1',
};
await menuManagementPage.fillMenuForm(menuData);
await menuManagementPage.submitForm();
await expect(menuManagementPage.successMessage).toBeVisible();
testDataCleanup.trackMenu(`business_${timestamp}`);
});
await test.step('3. 创建子级菜单', async () => {
await menuManagementPage.clickCreateMenu();
const menuData = {
menuName: `业务操作_${timestamp}`,
parentId: '1',
orderNum: '1',
menuType: 'C',
component: `business_operation_${timestamp}`,
perms: `business:operation_${timestamp}`,
status: '1',
};
await menuManagementPage.fillMenuForm(menuData);
await menuManagementPage.submitForm();
await expect(menuManagementPage.successMessage).toBeVisible();
});
await test.step('4. 配置菜单权限', async () => {
await menuManagementPage.editMenu(1);
await menuManagementPage.selectPermission('menu:view');
await menuManagementPage.selectPermission('menu:edit');
await menuManagementPage.submitForm();
await expect(menuManagementPage.successMessage).toBeVisible();
});
await test.step('5. 保存菜单配置', async () => {
await menuManagementPage.saveMenu();
await expect(menuManagementPage.successMessage).toBeVisible();
});
await test.step('6. 为角色分配菜单权限', async () => {
await dashboardPage.navigateToRoleManagement();
await roleManagementPage.openPermissionDialog(1);
await roleManagementPage.selectPermission(`business:view_${timestamp}`);
await roleManagementPage.submitPermissions();
await expect(roleManagementPage.successMessage).toBeVisible();
});
await test.step('7. 用户登录系统', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('8. 验证菜单显示', async () => {
await expect(page.locator('.menu-item')).toContainText(`业务菜单_${timestamp}`);
});
await test.step('9. 验证菜单访问', async () => {
await page.click(`text=业务菜单_${timestamp}`);
await expect(page).toHaveURL(/.*business/);
});
await test.step('10. 验证菜单结构', async () => {
await dashboardPage.navigateToMenuManagement();
await expect(page.locator('table')).toContainText(`业务菜单_${timestamp}`);
await expect(page.locator('table')).toContainText(`业务操作_${timestamp}`);
});
});
test('UAT-005: 文件管理场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const fileManagementPage = new FileManagementPage(page);
const timestamp = Date.now();
await test.step('1. 用户登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 导航到文件管理页面', async () => {
await dashboardPage.navigateToFileManagement();
await expect(fileManagementPage.table).toBeVisible();
});
await test.step('3. 上传文件', async () => {
await fileManagementPage.clickUploadFile();
const fileInput = page.locator('input[type="file"]');
await fileInput.setInputFiles('./e2e/fixtures/test-file.txt');
await fileManagementPage.submitUpload();
await expect(fileManagementPage.successMessage).toBeVisible();
});
await test.step('4. 验证文件上传成功', async () => {
await expect(page.locator('table')).toContainText('test-file.txt');
});
await test.step('5. 预览文件', async () => {
await fileManagementPage.previewFile(1);
await expect(page.locator('.file-preview')).toBeVisible();
await expect(page.locator('.file-preview')).toContainText('test');
});
await test.step('6. 下载文件', async () => {
const downloadPromise = page.waitForEvent('download');
await fileManagementPage.downloadFile(1);
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe('test-file.txt');
});
await test.step('7. 验证文件内容', async () => {
await fileManagementPage.previewFile(1);
const content = await page.locator('.file-preview').textContent();
expect(content).toContain('test');
});
await test.step('8. 设置文件权限', async () => {
await fileManagementPage.editFile(1);
await page.selectOption('select[name="permission"]', 'private');
await fileManagementPage.submitForm();
await expect(fileManagementPage.successMessage).toBeVisible();
});
await test.step('9. 删除文件', async () => {
await fileManagementPage.deleteFile(1);
await fileManagementPage.confirmDelete();
await expect(fileManagementPage.successMessage).toBeVisible();
});
await test.step('10. 验证文件删除', async () => {
await page.reload();
await expect(page.locator('table')).not.toContainText('test-file.txt');
});
});
test('UAT-006: 系统配置管理场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const systemConfigPage = new SystemConfigPage(page);
const timestamp = Date.now();
await test.step('1. 管理员登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 导航到系统配置页面', async () => {
await dashboardPage.navigateToSystemConfig();
await expect(systemConfigPage.table).toBeVisible();
});
await test.step('3. 查看当前配置', async () => {
const configCount = await page.locator('table tbody tr').count();
expect(configCount).toBeGreaterThan(0);
});
await test.step('4. 修改配置项', async () => {
await systemConfigPage.editConfig(1);
await page.fill('input[name="configValue"]', `test_config_${timestamp}`);
await systemConfigPage.submitForm();
await expect(systemConfigPage.successMessage).toBeVisible();
});
await test.step('5. 验证配置有效性', async () => {
await systemConfigPage.editConfig(1);
await expect(page.locator('input[name="configValue"]')).toHaveValue(`test_config_${timestamp}`);
});
await test.step('6. 保存配置', async () => {
await systemConfigPage.submitForm();
await expect(systemConfigPage.successMessage).toBeVisible();
});
await test.step('7. 验证配置生效', async () => {
await page.reload();
await expect(page.locator('table')).toContainText(`test_config_${timestamp}`);
});
await test.step('8. 刷新配置缓存', async () => {
await systemConfigPage.refreshCache();
await expect(systemConfigPage.successMessage).toBeVisible();
});
await test.step('9. 查看配置日志', async () => {
await dashboardPage.navigateToOperationLog();
await expect(page.locator('table')).toContainText('配置');
});
await test.step('10. 恢复默认配置', async () => {
await dashboardPage.navigateToSystemConfig();
await systemConfigPage.editConfig(1);
await page.fill('input[name="configValue"]', 'default_value');
await systemConfigPage.submitForm();
await expect(systemConfigPage.successMessage).toBeVisible();
});
});
test('UAT-007: 审计日志查询场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const operationLogPage = new OperationLogPage(page);
await test.step('1. 审计员登录系统', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('2. 导航到审计日志页面', async () => {
await dashboardPage.navigateToOperationLog();
await expect(operationLogPage.table).toBeVisible();
});
await test.step('3. 查看操作日志', async () => {
await expect(page.locator('table')).toContainText('操作');
});
await test.step('4. 查看登录日志', async () => {
await operationLogPage.switchToLoginLog();
await expect(page.locator('table')).toContainText('登录');
});
await test.step('5. 查看异常日志', async () => {
await operationLogPage.switchToExceptionLog();
await expect(operationLogPage.table).toBeVisible();
});
await test.step('6. 搜索日志', async () => {
await operationLogPage.search('admin');
await page.waitForTimeout(2000);
await expect(page.locator('table')).toContainText('admin');
});
await test.step('7. 导出日志', async () => {
const downloadPromise = page.waitForEvent('download');
await operationLogPage.exportLogs();
const download = await downloadPromise;
expect(download.suggestedFilename()).toMatch(/logs.*\.xlsx/);
});
await test.step('8. 验证日志准确性', async () => {
const logCount = await page.locator('table tbody tr').count();
expect(logCount).toBeGreaterThan(0);
});
await test.step('9. 生成审计报告', async () => {
await operationLogPage.generateReport();
await expect(operationLogPage.successMessage).toBeVisible();
});
await test.step('10. 验证报告内容', async () => {
await expect(page.locator('.report-content')).toBeVisible();
});
});
test('UAT-008: 通知中心使用场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const notificationPage = new NotificationPage(page);
const timestamp = Date.now();
await test.step('1. 管理员发布系统通知', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dashboardPage.navigateToNotification();
await notificationPage.clickCreateNotification();
const notificationData = {
title: `系统通知_${timestamp}`,
content: `这是一条重要的系统通知_${timestamp}`,
type: 'system',
status: '1',
};
await notificationPage.fillNotificationForm(notificationData);
await notificationPage.submitForm();
await expect(notificationPage.successMessage).toBeVisible();
});
await test.step('2. 用户登录系统', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('3. 查看通知列表', async () => {
await dashboardPage.navigateToNotification();
await expect(page.locator('.notification-list')).toBeVisible();
await expect(page.locator('.notification-list')).toContainText(`系统通知_${timestamp}`);
});
await test.step('4. 查看通知详情', async () => {
await notificationPage.viewNotification(1);
await expect(page.locator('.notification-detail')).toBeVisible();
await expect(page.locator('.notification-detail')).toContainText(`系统通知_${timestamp}`);
});
await test.step('5. 标记通知已读', async () => {
await notificationPage.markAsRead(1);
await expect(notificationPage.successMessage).toBeVisible();
});
await test.step('6. 验证通知状态', async () => {
await page.reload();
await expect(page.locator('.notification-item.read')).toBeVisible();
});
await test.step('7. 删除通知', async () => {
await notificationPage.deleteNotification(1);
await notificationPage.confirmDelete();
await expect(notificationPage.successMessage).toBeVisible();
});
await test.step('8. 验证通知删除', async () => {
await page.reload();
await expect(page.locator('.notification-list')).not.toContainText(`系统通知_${timestamp}`);
});
await test.step('9. 验证通知推送', async () => {
await notificationPage.clickCreateNotification();
const notificationData = {
title: `推送通知_${timestamp}`,
content: `这是一条推送通知_${timestamp}`,
type: 'push',
status: '1',
};
await notificationPage.fillNotificationForm(notificationData);
await notificationPage.submitForm();
await expect(notificationPage.successMessage).toBeVisible();
});
await test.step('10. 查看通知历史', async () => {
await page.reload();
await expect(page.locator('.notification-list')).toContainText(`推送通知_${timestamp}`);
});
});
test('UAT-009: 字典数据使用场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const dictionaryManagementPage = new DictionaryManagementPage(page);
const timestamp = Date.now();
await test.step('1. 管理员配置字典数据', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dashboardPage.navigateToDictionary();
await dictionaryManagementPage.clickCreateDictType();
const dictTypeData = {
dictName: `业务字典_${timestamp}`,
dictType: `business_dict_${timestamp}`,
status: '1',
remark: `业务字典类型_${timestamp}`,
};
await dictionaryManagementPage.fillDictTypeForm(dictTypeData);
await dictionaryManagementPage.submitForm();
await expect(dictionaryManagementPage.successMessage).toBeVisible();
testDataCleanup.trackDictType(`business_dict_${timestamp}`);
});
await test.step('2. 用户登录系统', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('3. 查看字典数据', async () => {
await dashboardPage.navigateToDictionary();
await expect(page.locator('table')).toContainText(`业务字典_${timestamp}`);
});
await test.step('4. 使用字典数据', async () => {
await dictionaryManagementPage.clickCreateDictData();
const dictData = {
dictLabel: `业务数据1_${timestamp}`,
dictValue: `business_value1_${timestamp}`,
dictSort: '1',
status: '1',
};
await dictionaryManagementPage.fillDictDataForm(dictData);
await dictionaryManagementPage.submitForm();
await expect(dictionaryManagementPage.successMessage).toBeVisible();
});
await test.step('5. 验证数据正确性', async () => {
await page.reload();
await expect(page.locator('table')).toContainText(`业务数据1_${timestamp}`);
});
await test.step('6. 管理员更新字典数据', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dashboardPage.navigateToDictionary();
await dictionaryManagementPage.editDictData(1);
await page.fill('input[name="dictLabel"]', `更新数据_${timestamp}`);
await dictionaryManagementPage.submitForm();
await expect(dictionaryManagementPage.successMessage).toBeVisible();
});
await test.step('7. 用户刷新页面', async () => {
await page.reload();
await expect(page.locator('table')).toContainText(`更新数据_${timestamp}`);
});
await test.step('8. 验证数据更新', async () => {
await expect(page.locator('table')).toContainText(`更新数据_${timestamp}`);
});
await test.step('9. 验证数据缓存', async () => {
await dictionaryManagementPage.refreshCache();
await expect(dictionaryManagementPage.successMessage).toBeVisible();
});
await test.step('10. 验证数据一致性', async () => {
await page.reload();
await expect(page.locator('table')).toContainText(`更新数据_${timestamp}`);
});
});
test('UAT-010: 多用户协作场景', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
const userManagementPage = new UserManagementPage(page);
const timestamp = Date.now();
await test.step('1. 创建测试用户A', async () => {
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await dashboardPage.navigateToUserManagement();
await userManagementPage.clickCreateUser();
const userData = {
username: `user_a_${timestamp}`,
nickname: `用户A_${timestamp}`,
email: `user_a_${timestamp}@example.com`,
phone: '13800138000',
password: 'Test123!@#',
confirmPassword: 'Test123!@#',
};
await userManagementPage.fillUserForm(userData);
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
testDataCleanup.trackUser(`user_a_${timestamp}`);
});
await test.step('2. 创建测试用户B', async () => {
await userManagementPage.clickCreateUser();
const userData = {
username: `user_b_${timestamp}`,
nickname: `用户B_${timestamp}`,
email: `user_b_${timestamp}@example.com`,
phone: '13800138000',
password: 'Test123!@#',
confirmPassword: 'Test123!@#',
};
await userManagementPage.fillUserForm(userData);
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
testDataCleanup.trackUser(`user_b_${timestamp}`);
});
await test.step('3. 多用户同时登录', async () => {
await loginPage.logout();
await loginPage.goto();
await loginPage.login('admin', 'admin123');
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('4. 用户A创建数据', async () => {
await dashboardPage.navigateToUserManagement();
await userManagementPage.clickCreateUser();
const userData = {
username: `data_a_${timestamp}`,
nickname: `数据A_${timestamp}`,
email: `data_a_${timestamp}@example.com`,
phone: '13800138000',
password: 'Test123!@#',
confirmPassword: 'Test123!@#',
};
await userManagementPage.fillUserForm(userData);
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
});
await test.step('5. 用户B同时创建数据', async () => {
await userManagementPage.clickCreateUser();
const userData = {
username: `data_b_${timestamp}`,
nickname: `数据B_${timestamp}`,
email: `data_b_${timestamp}@example.com`,
phone: '13800138000',
password: 'Test123!@#',
confirmPassword: 'Test123!@#',
};
await userManagementPage.fillUserForm(userData);
await userManagementPage.submitForm();
await expect(userManagementPage.successMessage).toBeVisible();
});
await test.step('6. 验证数据一致性', async () => {
await page.reload();
await expect(page.locator('table')).toContainText(`data_a_${timestamp}`);
await expect(page.locator('table')).toContainText(`data_b_${timestamp}`);
});
await test.step('7. 验证并发处理', async () => {
const userCount = await userManagementPage.getUserCount();
expect(userCount).toBeGreaterThanOrEqual(2);
});
await test.step('8. 查看操作日志', async () => {
await dashboardPage.navigateToOperationLog();
await expect(page.locator('table')).toContainText('创建');
});
await test.step('9. 验证日志完整性', async () => {
const logCount = await page.locator('table tbody tr').count();
expect(logCount).toBeGreaterThan(0);
});
await test.step('10. 清理测试数据', async () => {
await dashboardPage.navigateToUserManagement();
await userManagementPage.search(`user_a_${timestamp}`);
await page.waitForTimeout(1000);
const rows = await page.locator('table tbody tr').count();
if (rows > 0) {
await userManagementPage.deleteUser(1);
await userManagementPage.confirmDelete();
}
});
});
});
-205
View File
@@ -1,205 +0,0 @@
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/LoginPage';
import { DashboardPage } from './pages/DashboardPage';
test.describe('UAT阶段一:核心功能验证', () => {
test.slow();
test('UAT-AUTH-001: 成功登录流程', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('访问登录页面', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await expect(page).toHaveTitle(/登录/);
});
await test.step('输入用户名和密码', async () => {
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
});
await test.step('点击登录按钮', async () => {
await loginPage.loginButton.click();
});
await test.step('验证登录成功', async () => {
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const username = await dashboardPage.getUsername();
expect(username).toContain('admin');
});
});
test('UAT-AUTH-002: 登录失败 - 无效凭证', async ({ page }) => {
const loginPage = new LoginPage(page);
await test.step('访问登录页面', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await expect(page).toHaveTitle(/登录/);
});
await test.step('输入无效凭证', async () => {
await loginPage.usernameInput.fill('invalid');
await loginPage.passwordInput.fill('invalid');
await loginPage.loginButton.click();
});
await test.step('验证错误消息显示', async () => {
await page.waitForTimeout(2000);
const currentUrl = page.url();
expect(currentUrl).toContain('/login');
});
await test.step('验证保持在登录页面', async () => {
await expect(page).toHaveURL(/.*login/);
});
});
test('UAT-AUTH-003: 登出流程', async ({ page }) => {
const loginPage = new LoginPage(page);
await test.step('登录系统', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
await loginPage.loginButton.click();
await page.waitForURL(/.*dashboard/, { timeout: 30000 });
});
await test.step('点击用户头像', async () => {
const avatar = page.locator('.el-avatar');
await avatar.click();
await page.waitForSelector('.el-dropdown-menu', { state: 'visible' });
});
await test.step('点击退出登录', async () => {
const logoutButton = page.locator('.el-dropdown-menu').getByText('退出登录');
await logoutButton.click();
});
await test.step('验证跳转到登录页面', async () => {
await page.waitForURL(/.*login/, { timeout: 30000 });
await expect(page).toHaveTitle(/登录/);
});
});
test('UAT-NAV-001: 系统管理菜单导航', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('登录系统', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
await loginPage.loginButton.click();
await page.waitForURL(/.*dashboard/, { timeout: 30000 });
});
await test.step('点击系统管理菜单', async () => {
const systemMenu = page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
await systemMenu.click();
await page.waitForLoadState('networkidle');
});
await test.step('点击用户管理', async () => {
await dashboardPage.userManagementLink.click();
});
await test.step('验证页面跳转', async () => {
await page.waitForURL(/.*users/, { timeout: 30000 });
await expect(page).toHaveURL(/.*users/);
});
});
test('UAT-NAV-002: 角色管理菜单导航', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('登录系统', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
await loginPage.loginButton.click();
await page.waitForURL(/.*dashboard/, { timeout: 30000 });
});
await test.step('点击系统管理菜单', async () => {
const systemMenu = page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
await systemMenu.click();
await page.waitForLoadState('networkidle');
});
await test.step('点击角色管理', async () => {
await dashboardPage.roleManagementLink.click();
});
await test.step('验证页面跳转', async () => {
await page.waitForURL(/.*roles/, { timeout: 30000 });
await expect(page).toHaveURL(/.*roles/);
});
});
test('UAT-NAV-003: 菜单管理菜单导航', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('登录系统', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
await loginPage.loginButton.click();
await page.waitForURL(/.*dashboard/, { timeout: 30000 });
});
await test.step('点击系统管理菜单', async () => {
const systemMenu = page.locator('.el-sub-menu').filter({ hasText: '系统管理' });
await systemMenu.click();
await page.waitForLoadState('networkidle');
});
await test.step('点击菜单管理', async () => {
await dashboardPage.menuManagementLink.click();
});
await test.step('验证页面跳转', async () => {
await page.waitForURL(/.*menus/, { timeout: 30000 });
await expect(page).toHaveURL(/.*menus/);
});
});
test('UAT-NAV-004: 系统配置菜单导航', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('登录系统', async () => {
await loginPage.goto();
await page.waitForLoadState('networkidle');
await loginPage.usernameInput.fill('admin');
await loginPage.passwordInput.fill('admin123');
await loginPage.loginButton.click();
await page.waitForURL(/.*dashboard/, { timeout: 30000 });
});
await test.step('点击系统配置菜单', async () => {
const configMenu = page.locator('.el-sub-menu').filter({ hasText: '系统配置' });
await configMenu.click();
await page.waitForLoadState('networkidle');
});
await test.step('点击参数配置', async () => {
await dashboardPage.systemConfigLink.click();
});
await test.step('验证页面跳转', async () => {
await page.waitForURL(/.*sys\/config/, { timeout: 30000 });
await expect(page).toHaveURL(/.*sys\/config/);
});
});
});
@@ -1,78 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段二:用户管理功能验证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-USER-001: 用户列表加载', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
await expect(page.locator('.el-table__body-wrapper')).toBeVisible();
});
test('UAT-USER-002: 用户搜索功能', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const searchInput = page.locator('input[placeholder*="搜索"]').first();
if (await searchInput.isVisible()) {
await searchInput.fill('admin');
await page.waitForTimeout(1000);
await expect(page.locator('.el-table')).toBeVisible();
}
});
test('UAT-USER-003: 新增用户表单验证', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
await expect(page.locator('.el-dialog')).toBeVisible();
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
if (await confirmButton.isVisible()) {
await confirmButton.click();
await page.waitForTimeout(500);
const formErrors = page.locator('.el-form-item__error');
const errorCount = await formErrors.count();
expect(errorCount).toBeGreaterThan(0);
}
}
});
});
@@ -1,91 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段三:角色管理功能验证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-ROLE-001: 角色列表加载', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
});
test('UAT-ROLE-002: 新增角色表单验证', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
await expect(page.locator('.el-dialog')).toBeVisible();
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
if (await roleNameInput.isVisible()) {
await roleNameInput.fill('测试角色');
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
if (await roleKeyInput.isVisible()) {
await roleKeyInput.fill('test_role');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
if (await confirmButton.isVisible()) {
await confirmButton.click();
await page.waitForTimeout(1000);
}
}
}
}
});
test('UAT-ROLE-003: 角色权限分配', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const permissionButton = page.locator('button:has-text("权限")').first();
if (await permissionButton.isVisible()) {
await permissionButton.click();
await page.waitForTimeout(500);
await expect(page.locator('.el-dialog')).toBeVisible();
const tree = page.locator('.el-tree');
if (await tree.isVisible()) {
const firstCheckbox = tree.locator('.el-checkbox').first();
if (await firstCheckbox.isVisible()) {
await firstCheckbox.click();
}
}
}
});
});
@@ -1,110 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段四:菜单管理功能验证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-MENU-001: 菜单树形结构展示', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=菜单管理');
await page.waitForURL('**/menus', { timeout: 30000 });
await page.waitForLoadState('networkidle');
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
await page.waitForTimeout(1000);
const tableBody = page.locator('.el-table__body-wrapper');
await expect(tableBody).toBeVisible();
const emptyText = page.locator('text=暂无数据');
const hasEmptyText = await emptyText.isVisible().catch(() => false);
if (!hasEmptyText) {
const treeNodes = page.locator('.el-table__row');
const count = await treeNodes.count();
expect(count).toBeGreaterThanOrEqual(0);
}
});
test('UAT-MENU-002: 新增菜单表单验证', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=菜单管理');
await page.waitForURL('**/menus', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
await expect(page.locator('.el-dialog')).toBeVisible();
const menuNameInput = page.locator('.el-dialog input[placeholder*="菜单名称"]').first();
if (await menuNameInput.isVisible()) {
await menuNameInput.fill('测试菜单');
const permsInput = page.locator('.el-dialog input[placeholder*="路由地址"]').first();
if (await permsInput.isVisible()) {
await permsInput.fill('/test-menu');
const componentInput = page.locator('.el-dialog input[placeholder*="组件路径"]').first();
if (await componentInput.isVisible()) {
await componentInput.fill('views/test/TestMenu.vue');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
if (await confirmButton.isVisible()) {
await confirmButton.click();
await page.waitForTimeout(1000);
}
}
}
}
}
});
test('UAT-MENU-003: 菜单类型选择', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=菜单管理');
await page.waitForURL('**/menus', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const menuTypeSelect = page.locator('.el-dialog .el-select').first();
if (await menuTypeSelect.isVisible()) {
await menuTypeSelect.click();
await page.waitForTimeout(300);
const options = page.locator('.el-select-dropdown__item');
const count = await options.count();
expect(count).toBeGreaterThan(0);
}
}
});
});
@@ -1,97 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段五:API交互与错误处理验证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-API-001: Token过期处理', async ({ page }) => {
await page.evaluate(() => {
localStorage.removeItem('token');
});
await page.goto('/users');
await page.waitForTimeout(2000);
const currentUrl = page.url();
expect(currentUrl).toContain('/login');
});
test('UAT-API-002: 网络错误提示', async ({ page, context }) => {
await context.route('**/api/**', route => route.abort('failed'));
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForTimeout(2000);
await context.unroute('**/api/**');
});
test('UAT-API-003: 权限不足提示', async ({ page }) => {
await page.evaluate(() => {
localStorage.setItem('token', 'user_token_without_admin_rights');
});
await page.goto('/roles');
await page.waitForTimeout(1000);
const errorMessage = page.locator('.el-message--error');
if (await errorMessage.isVisible()) {
await expect(errorMessage).toBeVisible();
}
});
test('UAT-API-004: 并发请求处理', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
const refreshButton = page.locator('button:has-text("刷新")').first();
if (await refreshButton.isVisible()) {
for (let i = 0; i < 3; i++) {
await refreshButton.click();
await page.waitForTimeout(100);
}
await page.waitForTimeout(1000);
await expect(page.locator('.el-table')).toBeVisible();
}
});
test('UAT-API-005: 数据加载状态显示', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
const navigationPromise = page.click('text=用户管理');
const loading = page.locator('.el-loading-mask');
if (await loading.isVisible({ timeout: 100 }).catch(() => false)) {
await expect(loading).toBeVisible();
}
await navigationPromise;
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
await expect(page.locator('.el-table')).toBeVisible();
});
});
@@ -1,191 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段六:数据持久化验证', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-PERSIST-001: 角色创建持久化验证', async ({ page }) => {
const timestamp = Date.now();
const roleName = `测试角色_${timestamp}`;
const roleKey = `test_role_${timestamp}`;
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await roleNameInput.fill(roleName);
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill(roleKey);
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
await page.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const createdRole = page.locator(`text=${roleName}`);
await expect(createdRole).toBeVisible({ timeout: 5000 });
}
});
test('UAT-PERSIST-002: 用户创建持久化验证', async ({ page }) => {
const timestamp = Date.now();
const username = `testuser_${timestamp}`;
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const usernameInput = page.locator('.el-dialog input[placeholder*="用户名"]').first();
await usernameInput.fill(username);
const nicknameInput = page.locator('.el-dialog input[placeholder*="昵称"]').first();
await nicknameInput.fill(`测试用户_${timestamp}`);
const emailInput = page.locator('.el-dialog input[placeholder*="邮箱"]').first();
await emailInput.fill(`${username}@test.com`);
const phoneInput = page.locator('.el-dialog input[placeholder*="手机"]').first();
await phoneInput.fill('13800138000');
const passwordInput = page.locator('.el-dialog input[placeholder*="密码"]').first();
await passwordInput.fill('Test123456');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
await page.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const searchInput = page.locator('input[placeholder*="搜索"]').first();
if (await searchInput.isVisible()) {
await searchInput.fill(username);
await page.waitForTimeout(1000);
const createdUser = page.locator(`text=${username}`);
await expect(createdUser).toBeVisible({ timeout: 5000 });
}
}
});
test('UAT-PERSIST-003: 数据更新持久化验证', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const editButton = page.locator('button:has-text("编辑")').first();
if (await editButton.isVisible()) {
await editButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
const currentValue = await roleNameInput.inputValue();
const newValue = `${currentValue}_已修改_${Date.now()}`;
await roleNameInput.fill(newValue);
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
await page.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const updatedRole = page.locator(`text=${newValue}`);
await expect(updatedRole).toBeVisible({ timeout: 5000 });
}
});
test('UAT-PERSIST-004: 数据删除持久化验证', async ({ page }) => {
const timestamp = Date.now();
const roleName = `待删除角色_${timestamp}`;
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await roleNameInput.fill(roleName);
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill(`delete_test_${timestamp}`);
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
const createdRole = page.locator(`text=${roleName}`);
await createdRole.scrollIntoViewIfNeeded();
const deleteButton = page.locator(`tr:has-text("${roleName}") button:has-text("删除")`).first();
if (await deleteButton.isVisible()) {
await deleteButton.click();
await page.waitForTimeout(500);
const confirmDeleteButton = page.locator('.el-message-box button:has-text("确定")');
if (await confirmDeleteButton.isVisible()) {
await confirmDeleteButton.click();
await page.waitForTimeout(1000);
await page.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const deletedRole = page.locator(`text=${roleName}`);
await expect(deletedRole).not.toBeVisible({ timeout: 5000 });
}
}
}
});
});
@@ -1,228 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段七:边界条件与异常输入测试', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-BOUNDARY-001: 用户名超长输入测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const usernameInput = page.locator('.el-dialog input[placeholder*="用户名"]').first();
const longUsername = 'a'.repeat(300);
await usernameInput.fill(longUsername);
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const errorMessage = page.locator('.el-form-item__error, .el-message--error');
const hasError = await errorMessage.isVisible().catch(() => false);
expect(hasError).toBeTruthy();
}
});
test('UAT-BOUNDARY-002: 特殊字符输入测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await roleNameInput.fill('<script>alert("XSS")</script>');
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill("'; DROP TABLE roles; --");
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const errorMessage = page.locator('.el-form-item__error, .el-message--error');
const hasError = await errorMessage.isVisible().catch(() => false);
if (!hasError) {
const cancelButton = page.locator('.el-dialog button:has-text("取消")');
await cancelButton.click();
}
}
});
test('UAT-BOUNDARY-003: 空值输入测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const formErrors = page.locator('.el-form-item__error');
const errorCount = await formErrors.count();
expect(errorCount).toBeGreaterThan(0);
}
});
test('UAT-BOUNDARY-004: 邮箱格式验证测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const emailInput = page.locator('.el-dialog input[placeholder*="邮箱"]').first();
await emailInput.fill('invalid-email');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const emailError = page.locator('.el-form-item__error:has-text("邮箱")');
const hasError = await emailError.isVisible().catch(() => false);
expect(hasError).toBeTruthy();
}
});
test('UAT-BOUNDARY-005: 手机号格式验证测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const phoneInput = page.locator('.el-dialog input[placeholder*="手机"]').first();
await phoneInput.fill('123');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const phoneError = page.locator('.el-form-item__error:has-text("手机")');
const hasError = await phoneError.isVisible().catch(() => false);
expect(hasError).toBeTruthy();
}
});
test('UAT-BOUNDARY-006: Emoji表情输入测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await roleNameInput.fill('测试角色😀🎉🔥');
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill('test_emoji_role');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
const errorMessage = page.locator('.el-message--error');
const hasError = await errorMessage.isVisible().catch(() => false);
if (!hasError) {
const cancelButton = page.locator('.el-dialog button:has-text("取消")');
if (await cancelButton.isVisible()) {
await cancelButton.click();
}
}
}
});
test('UAT-BOUNDARY-007: 数字输入边界测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const sortInput = page.locator('.el-dialog input[type="number"]').first();
if (await sortInput.isVisible()) {
await sortInput.fill('-1');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const errorMessage = page.locator('.el-form-item__error');
const hasError = await errorMessage.isVisible().catch(() => false);
if (!hasError) {
const cancelButton = page.locator('.el-dialog button:has-text("取消")');
await cancelButton.click();
}
}
}
});
});
@@ -1,195 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('UAT阶段八:安全测试', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const usernameInput = page.locator('input[type="text"]').first();
const passwordInput = page.locator('input[type="password"]').first();
const loginButton = page.locator('button:has-text("登录")');
await usernameInput.fill('admin');
await passwordInput.fill('admin123');
await loginButton.click();
await page.waitForURL('**/dashboard', { timeout: 30000 });
await page.waitForLoadState('networkidle');
});
test('UAT-SECURITY-001: XSS攻击防护测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
const xssPayload = '<img src=x onerror=alert("XSS")>';
await roleNameInput.fill(xssPayload);
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill('xss_test');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
const errorMessage = page.locator('.el-form-item__error, .el-message--error');
const hasError = await errorMessage.isVisible().catch(() => false);
if (!hasError) {
const cancelButton = page.locator('.el-dialog button:has-text("取消")');
if (await cancelButton.isVisible()) {
await cancelButton.click();
}
}
expect(hasError).toBeTruthy();
}
});
test('UAT-SECURITY-002: SQL注入防护测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const searchInput = page.locator('input[placeholder*="搜索"]').first();
if (await searchInput.isVisible()) {
await searchInput.fill("admin' OR '1'='1");
await page.waitForTimeout(1000);
await expect(page.locator('.el-table')).toBeVisible();
const allRows = await page.locator('.el-table__row').count();
expect(allRows).toBeLessThan(100);
}
});
test('UAT-SECURITY-003: 未授权访问测试', async ({ page }) => {
await page.evaluate(() => {
localStorage.removeItem('token');
});
await page.goto('/users');
await page.waitForTimeout(2000);
const currentUrl = page.url();
expect(currentUrl).toContain('/login');
});
test('UAT-SECURITY-004: CSRF防护测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=角色管理');
await page.waitForURL('**/roles', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const roleNameInput = page.locator('.el-dialog input[placeholder*="角色名称"]').first();
await roleNameInput.fill('CSRF测试角色');
const roleKeyInput = page.locator('.el-dialog input[placeholder*="角色标识"]').first();
await roleKeyInput.fill('csrf_test');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(1000);
const successMessage = page.locator('.el-message--success');
const errorMessage = page.locator('.el-message--error');
const hasSuccess = await successMessage.isVisible().catch(() => false);
const hasError = await errorMessage.isVisible().catch(() => false);
expect(hasSuccess || hasError).toBeTruthy();
}
});
test('UAT-SECURITY-005: 密码强度验证测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
const addButton = page.locator('button:has-text("新增用户")').first();
if (await addButton.isVisible()) {
await addButton.click();
await page.waitForTimeout(500);
const usernameInput = page.locator('.el-dialog input[placeholder*="用户名"]').first();
await usernameInput.fill('testuser');
const passwordInput = page.locator('.el-dialog input[placeholder*="密码"]').first();
await passwordInput.fill('123');
const confirmButton = page.locator('.el-dialog button:has-text("确定")');
await confirmButton.click();
await page.waitForTimeout(500);
const passwordError = page.locator('.el-form-item__error');
const hasError = await passwordError.isVisible().catch(() => false);
expect(hasError).toBeTruthy();
}
});
test('UAT-SECURITY-006: 敏感信息泄露测试', async ({ page }) => {
await page.goto('/');
await page.waitForLoadState('networkidle');
const pageContent = await page.content();
expect(pageContent).not.toContain('password');
expect(pageContent).not.toContain('secret');
expect(pageContent).not.toContain('api_key');
expect(pageContent).not.toContain('private_key');
});
test('UAT-SECURITY-007: 会话超时测试', async ({ page }) => {
const systemMenu = page.locator('.el-sub-menu__title:has-text("系统管理")');
await systemMenu.click();
await page.waitForTimeout(1000);
await page.click('text=用户管理');
await page.waitForURL('**/users', { timeout: 30000 });
await page.waitForLoadState('networkidle');
await page.evaluate(() => {
const token = localStorage.getItem('token');
if (token) {
const expiredToken = token.replace(/\.(.*?)\./, '.expired.');
localStorage.setItem('token', expiredToken);
}
});
await page.reload();
await page.waitForTimeout(2000);
const currentUrl = page.url();
const isLoginPage = currentUrl.includes('/login');
const hasError = await page.locator('.el-message--error').isVisible().catch(() => false);
expect(isLoginPage || hasError).toBeTruthy();
});
});