Files
novalon-manage-system/novalon-manage-web/e2e/user-management.spec.ts
T
张翔 c50ccd258f feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests
style: 为Java类添加文档注释
docs: 更新.gitignore和配置文件
test: 添加性能测试和Playwright测试脚本
chore: 清理旧测试文件和配置
2026-03-14 13:49:39 +08:00

82 lines
2.8 KiB
TypeScript

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');
});
});