feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('用户认证 E2E 测试', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/login');
|
||||
});
|
||||
|
||||
test('成功登录流程', async ({ page }) => {
|
||||
await expect(page).toHaveTitle(/登录/);
|
||||
|
||||
await page.fill('input[placeholder*="用户名"]', 'admin');
|
||||
await page.fill('input[type="password"]', 'admin123');
|
||||
|
||||
await page.click('button:has-text("登录")');
|
||||
|
||||
await page.waitForURL('**/dashboard');
|
||||
await expect(page.locator('.user-info')).toContainText('admin');
|
||||
});
|
||||
|
||||
test('登录失败 - 无效凭证', async ({ page }) => {
|
||||
await page.fill('input[placeholder*="用户名"]', 'invalid');
|
||||
await page.fill('input[type="password"]', 'invalid');
|
||||
|
||||
await page.click('button:has-text("登录")');
|
||||
|
||||
await expect(page.locator('.error-message')).toBeVisible();
|
||||
await expect(page.locator('.error-message')).toContainText('用户名或密码错误');
|
||||
});
|
||||
|
||||
test('登录失败 - 缺少必填字段', async ({ page }) => {
|
||||
await page.fill('input[name="username"]', 'admin');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.error-message')).toBeVisible();
|
||||
});
|
||||
|
||||
test('登出流程', async ({ page }) => {
|
||||
await page.fill('input[name="username"]', 'admin');
|
||||
await page.fill('input[name="password"]', 'admin123');
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await page.waitForURL('**/');
|
||||
|
||||
await page.click('text=登出');
|
||||
|
||||
await page.waitForURL('**/login');
|
||||
await expect(page).toHaveTitle(/登录/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('角色管理 E2E 测试', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/login');
|
||||
await page.fill('input[placeholder*="用户名"]', 'admin');
|
||||
await page.fill('input[type="password"]', 'admin123');
|
||||
await page.click('button:has-text("登录")');
|
||||
await page.waitForURL('**/dashboard');
|
||||
});
|
||||
|
||||
test('创建角色完整流程', async ({ page }) => {
|
||||
await page.click('text=角色管理');
|
||||
await page.waitForURL('**/roles');
|
||||
|
||||
await page.click('text=创建角色');
|
||||
|
||||
const timestamp = Date.now();
|
||||
const roleName = `测试角色_${timestamp}`;
|
||||
const roleKey = `test_role_${timestamp}`;
|
||||
|
||||
await page.fill('input[name="roleName"]', roleName);
|
||||
await page.fill('input[name="roleKey"]', roleKey);
|
||||
await page.fill('input[name="roleSort"]', '1');
|
||||
|
||||
await page.click('input[type="checkbox"][value="user:view"]');
|
||||
await page.click('input[type="checkbox"][value="user:create"]');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText(roleName);
|
||||
});
|
||||
|
||||
test('编辑角色流程', async ({ page }) => {
|
||||
await page.click('text=角色管理');
|
||||
await page.waitForURL('**/roles');
|
||||
|
||||
await page.click('table tbody tr:first-child .edit-button');
|
||||
|
||||
await page.fill('input[name="roleName"]', '更新后的角色名称');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText('更新后的角色名称');
|
||||
});
|
||||
|
||||
test('分配权限流程', async ({ page }) => {
|
||||
await page.click('text=角色管理');
|
||||
await page.waitForURL('**/roles');
|
||||
|
||||
await page.click('table tbody tr:first-child .permission-button');
|
||||
|
||||
await page.click('input[type="checkbox"][value="user:edit"]');
|
||||
await page.click('input[type="checkbox"][value="user:delete"]');
|
||||
|
||||
await page.click('.permission-dialog .save-button');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
});
|
||||
|
||||
test('删除角色流程', async ({ page }) => {
|
||||
await page.click('text=角色管理');
|
||||
await page.waitForURL('**/roles');
|
||||
|
||||
const firstRow = page.locator('table tbody tr:first-child');
|
||||
const roleName = await firstRow.locator('td:first-child').textContent();
|
||||
|
||||
await firstRow.locator('.delete-button').click();
|
||||
|
||||
await page.click('.confirm-dialog .confirm-button');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('table')).not.toContainText(roleName);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('系统配置 E2E 测试', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/login');
|
||||
await page.fill('input[placeholder*="用户名"]', 'admin');
|
||||
await page.fill('input[type="password"]', 'admin123');
|
||||
await page.click('button:has-text("登录")');
|
||||
await page.waitForURL('**/dashboard');
|
||||
});
|
||||
|
||||
test('查看系统配置', async ({ page }) => {
|
||||
await page.click('text=系统配置');
|
||||
await page.waitForURL('**/config');
|
||||
|
||||
await expect(page.locator('table')).toBeVisible();
|
||||
await expect(page.locator('table tbody tr')).toHaveCount(10);
|
||||
});
|
||||
|
||||
test('编辑系统配置', async ({ page }) => {
|
||||
await page.click('text=系统配置');
|
||||
await page.waitForURL('**/config');
|
||||
|
||||
await page.click('table tbody tr:first-child .edit-button');
|
||||
|
||||
await page.fill('input[name="configValue"]', 'test_value_123');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
});
|
||||
|
||||
test('搜索配置项', async ({ page }) => {
|
||||
await page.click('text=系统配置');
|
||||
await page.waitForURL('**/config');
|
||||
|
||||
await page.fill('input[name="keyword"]', 'system');
|
||||
await page.click('button[type="search"]');
|
||||
|
||||
await expect(page.locator('table')).toContainText('system');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('用户管理 E2E 测试', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/login');
|
||||
await page.fill('input[placeholder*="用户名"]', 'admin');
|
||||
await page.fill('input[type="password"]', 'admin123');
|
||||
await page.click('button:has-text("登录")');
|
||||
await page.waitForURL('**/dashboard');
|
||||
});
|
||||
|
||||
test('创建用户完整流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
|
||||
await page.click('text=创建用户');
|
||||
|
||||
const timestamp = Date.now();
|
||||
const username = `testuser_${timestamp}`;
|
||||
|
||||
await page.fill('input[name="username"]', username);
|
||||
await page.fill('input[name="email"]', `test_${timestamp}@example.com`);
|
||||
await page.fill('input[name="phone"]', '13800138000');
|
||||
await page.fill('input[name="password"]', 'Test123!@#');
|
||||
await page.fill('input[name="confirmPassword"]', 'Test123!@#');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText(username);
|
||||
});
|
||||
|
||||
test('编辑用户流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
|
||||
await page.click('table tbody tr:first-child .edit-button');
|
||||
|
||||
await page.fill('input[name="email"]', 'updated@example.com');
|
||||
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
await expect(page.locator('table')).toContainText('updated@example.com');
|
||||
});
|
||||
|
||||
test('删除用户流程', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
|
||||
const firstRow = page.locator('table tbody tr:first-child');
|
||||
const username = await firstRow.locator('td:first-child').textContent();
|
||||
|
||||
await firstRow.locator('.delete-button').click();
|
||||
|
||||
await page.click('.confirm-dialog .confirm-button');
|
||||
|
||||
await expect(page.locator('.success-message')).toBeVisible();
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('table')).not.toContainText(username);
|
||||
});
|
||||
|
||||
test('搜索用户功能', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
|
||||
await page.fill('input[name="keyword"]', 'admin');
|
||||
await page.click('button[type="search"]');
|
||||
|
||||
await expect(page.locator('table')).toContainText('admin');
|
||||
});
|
||||
|
||||
test('分页功能', async ({ page }) => {
|
||||
await page.click('text=用户管理');
|
||||
await page.waitForURL('**/users');
|
||||
|
||||
await page.click('.pagination .next-page');
|
||||
|
||||
await expect(page.locator('.pagination .current-page')).toContainText('2');
|
||||
});
|
||||
});
|
||||
@@ -6,10 +6,11 @@ export default defineConfig({
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: process.env.CI ? 1 : undefined,
|
||||
reporter: 'html',
|
||||
reporter: 'list',
|
||||
use: {
|
||||
baseURL: 'http://localhost:3002',
|
||||
baseURL: 'http://localhost:3003',
|
||||
trace: 'on-first-retry',
|
||||
headless: true,
|
||||
},
|
||||
|
||||
projects: [
|
||||
|
||||
Reference in New Issue
Block a user