import { test, expect } from '@playwright/test'; import { LoginPage } from '../pages/LoginPage'; import { UserManagementPage } from '../pages/UserManagementPage'; import { SystemConfigPage } from '../pages/SystemConfigPage'; import { DictionaryManagementPage } from '../pages/DictionaryManagementPage'; import { NotificationPage } from '../pages/NotificationPage'; test.describe('UAT: 异常处理与边界条件', () => { test('UAT-ERR-01: 用户管理 - 重复用户名处理', async ({ page }) => { const loginPage = new LoginPage(page); const userPage = new UserManagementPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await userPage.goto(); await test.step('尝试创建已存在的用户名', async () => { await userPage.clickCreateUser(); await userPage.fillUserForm({ username: 'admin', password: 'Test@123456', nickname: '重复用户', email: 'duplicate@test.com', }); await userPage.submitForm(); }); await test.step('验证错误提示或表单验证', async () => { await page.waitForTimeout(2000); const hasError = (await page.locator('.ant-message-error').count()) > 0 || (await page.locator('.ant-form-item-explain-error').count()) > 0; expect(hasError).toBe(true); }); }); test('UAT-ERR-02: 用户管理 - 邮箱格式验证', async ({ page }) => { const loginPage = new LoginPage(page); const userPage = new UserManagementPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await userPage.goto(); await userPage.clickCreateUser(); await test.step('输入无效邮箱格式', async () => { const timestamp = Date.now(); await userPage.fillUserForm({ username: `err_user_${timestamp}`, password: 'Test@123456', nickname: '邮箱测试', email: 'invalid-email', }); }); await test.step('验证邮箱格式错误提示', async () => { await userPage.submitForm(); await page.waitForTimeout(1000); const hasValidationError = (await page.locator('.ant-form-item-explain-error').count()) > 0; expect(hasValidationError).toBe(true); }); }); test('UAT-ERR-03: 系统配置 - 空配置键验证', async ({ page }) => { const loginPage = new LoginPage(page); const configPage = new SystemConfigPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await configPage.goto(); await test.step('点击新增配置但不填写', async () => { await configPage.addButton.click(); await page.waitForTimeout(500); const modal = page.locator('.ant-modal').filter({ hasText: /新增配置/ }); await modal.getByRole('button', { name: '确 定' }).click(); }); await test.step('验证表单验证错误', async () => { await page.waitForTimeout(1000); const hasError = (await page.locator('.ant-form-item-explain-error').count()) > 0; expect(hasError).toBe(true); }); }); test('UAT-ERR-04: 字典管理 - 空字典名称验证', async ({ page }) => { const loginPage = new LoginPage(page); const dictPage = new DictionaryManagementPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await dictPage.goto(); await test.step('点击新增字典类型但不填写', async () => { await dictPage.addTypeButton.click(); await page.waitForTimeout(500); const modal = page.locator('.ant-modal').filter({ hasText: /新增字典类型/ }); await modal.getByRole('button', { name: '确 定' }).click(); }); await test.step('验证表单验证错误', async () => { await page.waitForTimeout(1000); const hasError = (await page.locator('.ant-form-item-explain-error').count()) > 0; expect(hasError).toBe(true); }); }); test('UAT-ERR-05: 通知管理 - 空标题验证', async ({ page }) => { const loginPage = new LoginPage(page); const notifyPage = new NotificationPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await notifyPage.goto(); await test.step('点击新增通知但不填写标题', async () => { await notifyPage.addButton.click(); await page.waitForTimeout(500); const modal = page.locator('.ant-modal').filter({ hasText: /新增通知/ }); await modal.locator('.ant-form-item').filter({ hasText: '内容' }).locator('textarea').fill('测试内容'); await modal.getByRole('button', { name: '确 定' }).click(); }); await test.step('验证表单验证错误', async () => { await page.waitForTimeout(1000); const hasError = (await page.locator('.ant-form-item-explain-error').count()) > 0; expect(hasError).toBe(true); }); }); test('UAT-ERR-06: 删除确认弹窗 - 取消操作', async ({ page }) => { const loginPage = new LoginPage(page); const userPage = new UserManagementPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await userPage.goto(); await userPage.waitForTableReady(); const countBefore = await userPage.getUserCount(); if (countBefore > 0) { await test.step('点击删除按钮', async () => { const row = userPage.table.locator('tbody tr').first(); await row.locator('.ant-btn').filter({ has: page.locator('.anticon-delete') }).click(); await page.waitForTimeout(300); }); await test.step('点击取消', async () => { const popconfirm = page.locator('.ant-popconfirm'); await popconfirm.getByRole('button', { name: '取 消' }).click(); await page.waitForTimeout(500); }); await test.step('验证数据未被删除', async () => { const countAfter = await userPage.getUserCount(); expect(countAfter).toBe(countBefore); }); } }); test('UAT-ERR-07: 模态框关闭 - 点击取消按钮', async ({ page }) => { const loginPage = new LoginPage(page); const userPage = new UserManagementPage(page); await loginPage.goto(); await loginPage.login('admin', 'admin123'); await userPage.goto(); await userPage.clickCreateUser(); await test.step('点击取消按钮关闭模态框', async () => { const modal = page.locator('.ant-modal').filter({ hasText: /新增用户/ }); await modal.getByRole('button', { name: '取 消' }).click(); await page.waitForTimeout(500); }); await test.step('验证模态框已关闭', async () => { const modalVisible = await page.locator('.ant-modal:visible').count(); expect(modalVisible).toBe(0); }); }); });