24422c2c19
- 增强前端表单验证规则(用户名、密码、邮箱、手机号) - 增强后端DTO验证注解(用户注册、角色创建) - 添加后端Handler验证逻辑(用户创建、角色创建) - 调整测试用例以适应系统实际情况 - 添加UAT测试套件(用户管理、角色管理、菜单管理、API交互、数据持久化、边界条件、安全测试) - 修改远程分支为 https://git.f.novalon.cn/novalon/novalon-manage-system.git
98 lines
3.2 KiB
TypeScript
98 lines
3.2 KiB
TypeScript
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();
|
|
});
|
|
});
|