be5d5ede90
refactor: 重构后端查询逻辑和API响应处理 fix: 修复用户角色更新和文件上传问题 test: 添加前端性能测试脚本和E2E测试用例 chore: 更新依赖版本和配置文件 docs: 添加环境检查脚本和测试文档 style: 统一表格标签样式和路由命名 perf: 优化前端页面加载速度和响应时间
306 lines
11 KiB
TypeScript
306 lines
11 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { LoginPage } from './pages/LoginPage';
|
|
import { DashboardPage } from './pages/DashboardPage';
|
|
import { NotificationPage } from './pages/NotificationPage';
|
|
|
|
test.describe('通知功能 E2E 测试', () => {
|
|
let loginPage: LoginPage;
|
|
let dashboardPage: DashboardPage;
|
|
let notificationPage: NotificationPage;
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
loginPage = new LoginPage(page);
|
|
dashboardPage = new DashboardPage(page);
|
|
notificationPage = new NotificationPage(page);
|
|
});
|
|
|
|
test('NOTIFY-001: 管理员查看通知列表', async ({ page }) => {
|
|
await test.step('管理员登录', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
|
|
await test.step('导航到通知管理页面', async () => {
|
|
await page.goto('/notice');
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
|
|
await test.step('验证通知列表页面加载', async () => {
|
|
await expect(notificationPage.table).toBeVisible();
|
|
const rowCount = await notificationPage.getTableRowCount();
|
|
expect(rowCount).toBeGreaterThanOrEqual(0);
|
|
});
|
|
|
|
await test.step('验证通知表格包含必要列', async () => {
|
|
await expect(notificationPage.table).toContainText('通知标题');
|
|
await expect(notificationPage.table).toContainText('通知类型');
|
|
await expect(notificationPage.table).toContainText('状态');
|
|
await expect(notificationPage.table).toContainText('创建时间');
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-002: 管理员新增通知', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('新增通知', async () => {
|
|
const testTitle = `测试通知_${Date.now()}`;
|
|
const testContent = `这是一个测试通知内容,创建时间:${new Date().toLocaleString()}`;
|
|
|
|
await notificationPage.addNotification(testTitle, testContent);
|
|
await page.waitForTimeout(1000);
|
|
|
|
await expect(notificationPage.table).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-003: 管理员修改通知', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('修改通知', async () => {
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
if (rows > 0) {
|
|
const firstRow = notificationPage.table.locator('.el-table__row').first();
|
|
const title = await firstRow.locator('td').nth(1).textContent();
|
|
|
|
if (title && title.includes('测试通知')) {
|
|
const newContent = `更新后的通知内容,时间:${new Date().toLocaleString()}`;
|
|
await notificationPage.editNotification(title, newContent);
|
|
await page.waitForTimeout(1000);
|
|
|
|
await expect(notificationPage.table).toBeVisible();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-004: 管理员删除通知', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('删除通知', async () => {
|
|
const testRow = notificationPage.table.locator('tr').filter({ hasText: '测试通知' }).first();
|
|
const testRowCount = await testRow.count();
|
|
|
|
if (testRowCount > 0) {
|
|
const title = await testRow.locator('td').nth(1).textContent();
|
|
|
|
if (title) {
|
|
await notificationPage.deleteNotification(title);
|
|
await page.waitForTimeout(1000);
|
|
|
|
await expect(notificationPage.table).toBeVisible();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-005: 管理员搜索通知', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('搜索通知', async () => {
|
|
await notificationPage.searchNotification('测试');
|
|
await page.waitForTimeout(1000);
|
|
});
|
|
|
|
await test.step('清除搜索条件', async () => {
|
|
await notificationPage.clearSearch();
|
|
const rowCount = await notificationPage.getTableRowCount();
|
|
expect(rowCount).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-006: 验证通知权限控制', async ({ page }) => {
|
|
await test.step('普通用户登录', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('user', 'user123');
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
|
|
await test.step('尝试访问通知管理页面', async () => {
|
|
await page.goto('/notice');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
const currentURL = page.url();
|
|
if (currentURL.includes('/notice')) {
|
|
await expect(notificationPage.table).toBeVisible();
|
|
} else {
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-007: 验证通知状态管理', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证通知状态显示', async () => {
|
|
await expect(notificationPage.table).toContainText('状态');
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
expect(rows).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-008: 验证通知类型分类', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证通知类型显示', async () => {
|
|
await expect(notificationPage.table).toContainText('通知类型');
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
expect(rows).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-009: 验证通知创建时间显示', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证创建时间显示', async () => {
|
|
await expect(notificationPage.table).toContainText('创建时间');
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
expect(rows).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-010: 验证通知操作按钮可见性', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证新增按钮可见', async () => {
|
|
await expect(notificationPage.addButton).toBeVisible();
|
|
});
|
|
|
|
await test.step('验证搜索框可见', async () => {
|
|
await expect(notificationPage.searchInput).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-011: 验证通知内容完整性', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证通知内容显示', async () => {
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
if (rows > 0) {
|
|
const firstRow = notificationPage.table.locator('.el-table__row').first();
|
|
await expect(firstRow).toBeVisible();
|
|
}
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-012: 验证通知标题必填验证', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('点击新增按钮', async () => {
|
|
await notificationPage.addButton.click();
|
|
await page.waitForTimeout(500);
|
|
});
|
|
|
|
await test.step('不填写标题直接保存', async () => {
|
|
await notificationPage.saveButton.click();
|
|
await page.waitForTimeout(500);
|
|
|
|
const errorMessage = page.locator('.el-message--error');
|
|
const errorCount = await errorMessage.count();
|
|
expect(errorCount).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-013: 验证通知内容必填验证', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('点击新增按钮', async () => {
|
|
await notificationPage.addButton.click();
|
|
await page.waitForTimeout(500);
|
|
});
|
|
|
|
await test.step('填写标题但不填写内容', async () => {
|
|
await notificationPage.titleInput.fill('测试标题');
|
|
await notificationPage.saveButton.click();
|
|
await page.waitForTimeout(500);
|
|
|
|
const errorMessage = page.locator('.el-message--error');
|
|
const errorCount = await errorMessage.count();
|
|
expect(errorCount).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-014: 验证通知删除确认', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('删除通知并确认', async () => {
|
|
const testRow = notificationPage.table.locator('tr').filter({ hasText: '测试通知' }).first();
|
|
const testRowCount = await testRow.count();
|
|
|
|
if (testRowCount > 0) {
|
|
const title = await testRow.locator('td').nth(1).textContent();
|
|
|
|
if (title) {
|
|
await notificationPage.deleteNotification(title);
|
|
await page.waitForTimeout(1000);
|
|
|
|
await expect(notificationPage.table).toBeVisible();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
test('NOTIFY-015: 验证通知列表排序', async ({ page }) => {
|
|
await test.step('管理员登录并导航到通知管理', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await notificationPage.goto();
|
|
});
|
|
|
|
await test.step('验证通知按创建时间排序', async () => {
|
|
const firstRow = notificationPage.table.locator('.el-table__row').first();
|
|
await expect(firstRow).toBeVisible();
|
|
|
|
const rows = await notificationPage.table.locator('.el-table__row').count();
|
|
expect(rows).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
}); |