refactor(tests): 迁移 E2E 测试到独立的 e2e-tests 目录
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('管理员完整工作流', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
const timestamp = Date.now();
|
||||
const roleName = `测试角色_${timestamp}`;
|
||||
const roleKey = `test_role_${timestamp}`;
|
||||
const username = `testuser_${timestamp}`;
|
||||
|
||||
test('创建角色并分配权限', async ({ page }) => {
|
||||
await test.step('导航到角色管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=角色管理').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*roles/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击创建角色按钮', async () => {
|
||||
await page.locator('button:has-text("新增角色")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写角色信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(roleName);
|
||||
await dialog.locator('input').nth(1).fill(roleKey);
|
||||
await dialog.locator('.el-input-number .el-input__inner').fill('99');
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('创建用户并分配角色', async ({ page }) => {
|
||||
await test.step('导航到用户管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=用户管理').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*users/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击创建用户按钮', async () => {
|
||||
await page.locator('button:has-text("新增用户")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写用户信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(username);
|
||||
await dialog.locator('input[type="password"]').fill('Test@123');
|
||||
await dialog.locator('input').nth(2).fill(`测试用户${timestamp}`);
|
||||
await dialog.locator('input').nth(3).fill(`test_${timestamp}@example.com`);
|
||||
await dialog.locator('input').nth(4).fill('13800138000');
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('搜索新创建的用户', async () => {
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const searchInput = page.locator('input[placeholder*="搜索"]');
|
||||
await searchInput.waitFor({ state: 'visible', timeout: 5000 });
|
||||
await searchInput.fill(username);
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(2000);
|
||||
});
|
||||
|
||||
await test.step('分配角色', async () => {
|
||||
const userRow = page.locator(`tr:has-text("${username}")`);
|
||||
await expect(userRow).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await userRow.locator('button:has-text("分配角色")').click();
|
||||
await page.waitForSelector('.el-dialog:has-text("分配角色")', { state: 'visible', timeout: 5000 });
|
||||
|
||||
const transfer = page.locator('.el-transfer');
|
||||
const leftPanel = transfer.locator('.el-transfer-panel').first();
|
||||
const rightPanel = transfer.locator('.el-transfer-panel').last();
|
||||
|
||||
const rightPanelItems = await rightPanel.locator('.el-checkbox').all();
|
||||
let hasSuperAdminRole = false;
|
||||
|
||||
for (const item of rightPanelItems) {
|
||||
const text = await item.textContent();
|
||||
if (text?.includes('超级管理员')) {
|
||||
hasSuperAdminRole = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSuperAdminRole) {
|
||||
const leftPanelItems = await leftPanel.locator('.el-checkbox').all();
|
||||
let superAdminCheckbox = null;
|
||||
|
||||
for (const item of leftPanelItems) {
|
||||
const text = await item.textContent();
|
||||
if (text?.includes('超级管理员')) {
|
||||
superAdminCheckbox = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (superAdminCheckbox) {
|
||||
const isChecked = await superAdminCheckbox.locator('input').isChecked();
|
||||
if (!isChecked) {
|
||||
await superAdminCheckbox.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
const moveToRightButton = transfer.locator('.el-transfer__buttons button').nth(1);
|
||||
if (await moveToRightButton.isEnabled()) {
|
||||
await moveToRightButton.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await page.locator('.el-dialog:has-text("分配角色") button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog:has-text("分配角色")', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success').last()).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('验证新用户登录', async ({ page }) => {
|
||||
await test.step('管理员登出', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const avatarButton = page.locator('.el-avatar').first();
|
||||
await avatarButton.click({ timeout: 10000 });
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.locator('text=退出登录').click();
|
||||
await page.waitForURL(/.*login/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('新用户登录', async () => {
|
||||
await page.goto('/login');
|
||||
await page.locator('input[placeholder*="用户名"]').fill(username);
|
||||
await page.locator('input[placeholder*="密码"]').fill('Test@123');
|
||||
await page.locator('button:has-text("登录")').click();
|
||||
await page.waitForURL('**/dashboard', { timeout: 30000 });
|
||||
});
|
||||
|
||||
await test.step('验证用户已登录', async () => {
|
||||
await expect(page).toHaveURL(/.*dashboard/);
|
||||
});
|
||||
});
|
||||
|
||||
test.skip('清理测试数据', async ({ page }) => {
|
||||
await test.step('管理员重新登录', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const avatarButton = page.locator('.el-avatar').first();
|
||||
if (await avatarButton.isVisible()) {
|
||||
await avatarButton.click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=退出登录').click();
|
||||
}
|
||||
|
||||
await page.goto('/login');
|
||||
await page.locator('input[placeholder*="用户名"]').fill('admin');
|
||||
await page.locator('input[placeholder*="密码"]').fill('Test@123');
|
||||
await page.locator('button:has-text("登录")').click();
|
||||
await page.waitForURL('**/dashboard');
|
||||
});
|
||||
|
||||
await test.step('删除测试用户', async () => {
|
||||
await page.goto('/users');
|
||||
await page.locator('input[placeholder*="搜索"]').fill(username);
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.locator('button:has-text("删除")').first().click();
|
||||
await page.locator('button:has-text("确定")').click();
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('删除测试角色', async () => {
|
||||
await page.goto('/roles');
|
||||
await page.locator('input[placeholder*="搜索"]').fill(roleName);
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
await page.locator('button:has-text("删除")').first().click();
|
||||
await page.locator('button:has-text("确定")').click();
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('审计工作流', () => {
|
||||
test('执行操作并查看操作日志', async ({ page }) => {
|
||||
await test.step('执行用户管理操作', async () => {
|
||||
await page.goto('/users');
|
||||
await page.waitForTimeout(1000);
|
||||
});
|
||||
|
||||
await test.step('执行角色管理操作', async () => {
|
||||
await page.goto('/roles');
|
||||
await page.waitForTimeout(1000);
|
||||
});
|
||||
|
||||
await test.step('执行菜单管理操作', async () => {
|
||||
await page.goto('/menus');
|
||||
await page.waitForTimeout(1000);
|
||||
});
|
||||
|
||||
await test.step('导航到操作日志', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('text=审计日志').click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.locator('.el-menu-item:has-text("操作日志")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await expect(page).toHaveURL(/.*oplog/, { timeout: 10000 });
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证操作日志记录', async () => {
|
||||
await page.waitForTimeout(2000);
|
||||
const logContent = await page.locator('.el-table').textContent();
|
||||
expect(logContent).toMatch(/用户管理|角色管理|菜单管理/);
|
||||
});
|
||||
});
|
||||
|
||||
test('查看登录日志', async ({ page }) => {
|
||||
await test.step('导航到登录日志', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('text=审计日志').click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.locator('.el-menu-item:has-text("登录日志")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await expect(page).toHaveURL(/.*loginlog/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证登录日志显示', async () => {
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
const logContent = await page.locator('.el-table').textContent();
|
||||
expect(logContent).toBeTruthy();
|
||||
expect(logContent.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('搜索和筛选日志', async ({ page }) => {
|
||||
await test.step('导航到操作日志', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('text=审计日志').click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.locator('.el-menu-item:has-text("操作日志")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('按模块筛选', async () => {
|
||||
const moduleSelect = page.locator('.el-select:has-text("模块")');
|
||||
if (await moduleSelect.isVisible()) {
|
||||
await moduleSelect.click();
|
||||
await page.locator('.el-select-dropdown__item:has-text("用户管理")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('按时间范围筛选', async () => {
|
||||
const dateRangePicker = page.locator('.el-date-editor');
|
||||
if (await dateRangePicker.isVisible()) {
|
||||
await dateRangePicker.click();
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('搜索特定内容', async () => {
|
||||
const searchInput = page.locator('input[placeholder*="搜索"]');
|
||||
if (await searchInput.isVisible()) {
|
||||
await searchInput.fill('admin');
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { SystemConfigPage } from '../pages/SystemConfigPage';
|
||||
|
||||
test.describe('系统配置工作流', () => {
|
||||
let configPage: SystemConfigPage;
|
||||
const timestamp = Date.now();
|
||||
const configKey = `test_config_${timestamp}`;
|
||||
const configName = `测试配置_${timestamp}`;
|
||||
const configValue = `测试值_${timestamp}`;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
configPage = new SystemConfigPage(page);
|
||||
});
|
||||
|
||||
test('查看系统配置列表', async ({ page }) => {
|
||||
await test.step('导航到系统配置页面', async () => {
|
||||
await configPage.goto();
|
||||
});
|
||||
|
||||
await test.step('验证表格显示', async () => {
|
||||
await expect(configPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证数据加载', async () => {
|
||||
const rowCount = await configPage.getTableRowCount();
|
||||
console.log(`系统配置列表包含 ${rowCount} 条记录`);
|
||||
expect(rowCount).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('新增系统配置', async ({ page }) => {
|
||||
await test.step('导航到系统配置页面', async () => {
|
||||
await configPage.goto();
|
||||
});
|
||||
|
||||
await test.step('点击新增配置按钮', async () => {
|
||||
await configPage.addButton.click();
|
||||
await configPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写配置表单', async () => {
|
||||
await configPage.configNameInput.fill(configName);
|
||||
await configPage.configKeyInput.fill(configKey);
|
||||
await configPage.configValueInput.fill(configValue);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await configPage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证创建成功', async () => {
|
||||
await expect(configPage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`配置 ${configName} 创建完成`);
|
||||
});
|
||||
});
|
||||
|
||||
test('编辑系统配置', async ({ page }) => {
|
||||
await test.step('导航到系统配置页面', async () => {
|
||||
await configPage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(configPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击编辑按钮', async () => {
|
||||
const rows = await configPage.getTableRowCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = configPage.table.locator('tr').first();
|
||||
const editBtn = firstRow.getByRole('button', { name: '编辑' });
|
||||
if (await editBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await editBtn.click();
|
||||
await configPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
|
||||
await test.step('修改配置值', async () => {
|
||||
const newValue = `更新值_${timestamp}`;
|
||||
await configPage.configValueInput.clear();
|
||||
await configPage.configValueInput.fill(newValue);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await configPage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证更新成功', async () => {
|
||||
await expect(configPage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`配置已更新`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到编辑按钮,跳过编辑测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有配置记录,跳过编辑测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('删除系统配置', async ({ page }) => {
|
||||
await test.step('导航到系统配置页面', async () => {
|
||||
await configPage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(configPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击删除按钮', async () => {
|
||||
const rows = await configPage.getTableRowCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = configPage.table.locator('tr').first();
|
||||
const deleteBtn = firstRow.getByRole('button', { name: '删除' });
|
||||
if (await deleteBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await deleteBtn.click();
|
||||
const confirmBtn = page.locator('.el-message-box');
|
||||
await confirmBtn.waitFor({ state: 'visible', timeout: 3000 });
|
||||
|
||||
await test.step('确认删除', async () => {
|
||||
const confirmBtn = page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
if (await confirmBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||||
await confirmBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('验证删除成功', async () => {
|
||||
const messageBox = page.locator('.el-message-box');
|
||||
await expect(messageBox).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`配置已删除`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到删除按钮,跳过删除测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有配置记录,跳过删除测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { DictionaryManagementPage } from '../pages/DictionaryManagementPage';
|
||||
|
||||
test.describe('字典管理工作流', () => {
|
||||
let dictPage: DictionaryManagementPage;
|
||||
const timestamp = Date.now();
|
||||
const dictType = `test_dict_${timestamp}`;
|
||||
const dictName = `测试字典_${timestamp}`;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
dictPage = new DictionaryManagementPage(page);
|
||||
});
|
||||
|
||||
test('查看字典列表', async ({ page }) => {
|
||||
await test.step('导航到字典管理页面', async () => {
|
||||
await dictPage.goto();
|
||||
});
|
||||
|
||||
await test.step('验证表格显示', async () => {
|
||||
await expect(dictPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证数据加载', async () => {
|
||||
const rowCount = await dictPage.getDictCount();
|
||||
console.log(`字典列表包含 ${rowCount} 条记录`);
|
||||
expect(rowCount).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('新增字典', async ({ page }) => {
|
||||
await test.step('导航到字典管理页面', async () => {
|
||||
await dictPage.goto();
|
||||
});
|
||||
|
||||
await test.step('点击新增字典按钮', async () => {
|
||||
await dictPage.createDictButton.click();
|
||||
await dictPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写字典表单', async () => {
|
||||
await dictPage.dictNameInput.fill(dictName);
|
||||
await dictPage.dictTypeInput.fill(dictType);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await dictPage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证创建成功', async () => {
|
||||
await expect(dictPage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`字典 ${dictName} 创建完成`);
|
||||
});
|
||||
});
|
||||
|
||||
test('编辑字典', async ({ page }) => {
|
||||
await test.step('导航到字典管理页面', async () => {
|
||||
await dictPage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(dictPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击编辑按钮', async () => {
|
||||
const rows = await dictPage.getDictCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = dictPage.table.locator('tr').first();
|
||||
const editBtn = firstRow.getByRole('button', { name: '编辑' });
|
||||
if (await editBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await editBtn.click();
|
||||
await dictPage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
|
||||
await test.step('修改字典名称', async () => {
|
||||
const newName = `更新字典_${timestamp}`;
|
||||
await dictPage.dictNameInput.clear();
|
||||
await dictPage.dictNameInput.fill(newName);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await dictPage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证更新成功', async () => {
|
||||
await expect(dictPage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`字典已更新`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到编辑按钮,跳过编辑测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有字典记录,跳过编辑测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('删除字典', async ({ page }) => {
|
||||
await test.step('导航到字典管理页面', async () => {
|
||||
await dictPage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(dictPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击删除按钮', async () => {
|
||||
const rows = await dictPage.getDictCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = dictPage.table.locator('tr').first();
|
||||
const deleteBtn = firstRow.getByRole('button', { name: '删除' });
|
||||
if (await deleteBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await deleteBtn.click();
|
||||
const confirmBtn = page.locator('.el-message-box');
|
||||
await confirmBtn.waitFor({ state: 'visible', timeout: 3000 });
|
||||
|
||||
await test.step('确认删除', async () => {
|
||||
const confirmBtn = page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
if (await confirmBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||||
await confirmBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('验证删除成功', async () => {
|
||||
const messageBox = page.locator('.el-message-box');
|
||||
await expect(messageBox).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`字典已删除`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到删除按钮,跳过删除测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有字典记录,跳过删除测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,253 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('数据字典管理完整工作流', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
const timestamp = Date.now();
|
||||
const dictType = `test_dict_type_${timestamp}`;
|
||||
const dictName = `测试字典_${timestamp}`;
|
||||
const dictCode = `test_dict_code_${timestamp}`;
|
||||
|
||||
test('创建字典类型', async ({ page }) => {
|
||||
await test.step('导航到数据字典管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=数据字典').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*dicts/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('切换到字典类型标签页', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典类型")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('点击新增字典类型按钮', async () => {
|
||||
await page.locator('button:has-text("新增字典类型")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写字典类型信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(dictType);
|
||||
await dialog.locator('input').nth(1).fill(`测试字典类型_${timestamp}`);
|
||||
await dialog.locator('textarea').fill(`这是测试字典类型的备注信息,时间戳:${timestamp}`);
|
||||
});
|
||||
|
||||
await test.step('提交字典类型表单', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证字典类型已创建', async () => {
|
||||
await page.locator('input[placeholder="请输入字典类型"]').fill(dictType);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const dictTypeRow = page.locator(`tr:has-text("${dictType}")`);
|
||||
await expect(dictTypeRow).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('创建字典数据', async ({ page }) => {
|
||||
await test.step('导航到数据字典管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=数据字典').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('切换到字典数据标签页', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典数据")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('点击新增字典数据按钮', async () => {
|
||||
await page.locator('button:has-text("新增字典数据")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写字典数据信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
|
||||
// 选择字典类型
|
||||
await dialog.locator('.el-select').first().click();
|
||||
await page.locator(`.el-select-dropdown:visible .el-select-dropdown__item:has-text("${dictType}")`).click();
|
||||
|
||||
await dialog.locator('input').nth(1).fill(dictName);
|
||||
await dialog.locator('input').nth(2).fill(dictCode);
|
||||
await dialog.locator('.el-input-number .el-input__inner').fill('99');
|
||||
await dialog.locator('textarea').fill(`这是测试字典数据的备注信息,时间戳:${timestamp}`);
|
||||
});
|
||||
|
||||
await test.step('提交字典数据表单', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证字典数据已创建', async () => {
|
||||
await page.locator('input[placeholder="请输入字典名称"]').fill(dictName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const dictDataRow = page.locator(`tr:has-text("${dictName}")`);
|
||||
await expect(dictDataRow).toBeVisible({ timeout: 10000 });
|
||||
await expect(dictDataRow.locator('td').nth(2)).toHaveText(dictCode);
|
||||
});
|
||||
});
|
||||
|
||||
test('编辑字典数据', async ({ page }) => {
|
||||
const updatedName = `更新字典_${timestamp}`;
|
||||
|
||||
await test.step('导航到数据字典管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=数据字典').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('切换到字典数据标签页', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典数据")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('搜索并编辑字典数据', async () => {
|
||||
await page.locator('input[placeholder="请输入字典名称"]').fill(dictName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const dictDataRow = page.locator(`tr:has-text("${dictName}")`);
|
||||
await dictDataRow.locator('button:has-text("编辑")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('修改字典数据信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').nth(1).fill(updatedName);
|
||||
await dialog.locator('textarea').fill(`这是更新后的字典数据备注,时间戳:${timestamp}`);
|
||||
});
|
||||
|
||||
await test.step('提交更新', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证字典数据已更新', async () => {
|
||||
await page.locator('input[placeholder="请输入字典名称"]').fill(updatedName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const dictDataRow = page.locator(`tr:has-text("${updatedName}")`);
|
||||
await expect(dictDataRow).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('删除字典数据', async ({ page }) => {
|
||||
await test.step('导航到数据字典管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=数据字典').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('切换到字典数据标签页', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典数据")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('搜索并删除字典数据', async () => {
|
||||
await page.locator('input[placeholder="请输入字典名称"]').fill(`更新字典_${timestamp}`);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const dictDataRow = page.locator(`tr:has-text("更新字典_${timestamp}")`);
|
||||
await dictDataRow.locator('button:has-text("删除")').click();
|
||||
await page.waitForSelector('.el-message-box', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('确认删除', async () => {
|
||||
await page.locator('.el-message-box button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-message-box', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证字典数据已删除', async () => {
|
||||
await page.locator('input[placeholder="请输入字典名称"]').fill(`更新字典_${timestamp}`);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const emptyText = page.locator('text=暂无数据');
|
||||
await expect(emptyText).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('字典管理功能验证', async ({ page }) => {
|
||||
await test.step('验证字典管理页面访问权限', async () => {
|
||||
await page.goto('/dicts');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证页面标题
|
||||
await expect(page.locator('h1:has-text("数据字典管理")')).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// 验证标签页
|
||||
await expect(page.locator('.el-tabs__item:has-text("字典类型")')).toBeVisible();
|
||||
await expect(page.locator('.el-tabs__item:has-text("字典数据")')).toBeVisible();
|
||||
|
||||
// 验证功能按钮
|
||||
await expect(page.locator('button:has-text("新增字典类型")')).toBeVisible();
|
||||
await expect(page.locator('button:has-text("新增字典数据")')).toBeVisible();
|
||||
await expect(page.locator('button:has-text("查询")')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('验证字典类型搜索功能', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典类型")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const searchInput = page.locator('input[placeholder="请输入字典类型"]');
|
||||
await expect(searchInput).toBeVisible();
|
||||
|
||||
const searchButton = page.locator('button:has-text("查询")');
|
||||
await expect(searchButton).toBeVisible();
|
||||
|
||||
// 测试搜索功能
|
||||
await searchInput.fill('test');
|
||||
await searchButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证搜索结果
|
||||
const table = page.locator('.el-table');
|
||||
await expect(table).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('验证字典数据搜索功能', async () => {
|
||||
await page.locator('.el-tabs__item:has-text("字典数据")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const searchInput = page.locator('input[placeholder="请输入字典名称"]');
|
||||
await expect(searchInput).toBeVisible();
|
||||
|
||||
const searchButton = page.locator('button:has-text("查询")');
|
||||
await expect(searchButton).toBeVisible();
|
||||
|
||||
// 测试搜索功能
|
||||
await searchInput.fill('test');
|
||||
await searchButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证搜索结果
|
||||
const table = page.locator('.el-table');
|
||||
await expect(table).toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { ExceptionLogPage } from '../pages/ExceptionLogPage';
|
||||
|
||||
test.describe('异常日志工作流', () => {
|
||||
let exceptionLogPage: ExceptionLogPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
exceptionLogPage = new ExceptionLogPage(page);
|
||||
});
|
||||
|
||||
test('查看异常日志列表', async ({ page }) => {
|
||||
await test.step('导航到异常日志页面', async () => {
|
||||
await exceptionLogPage.goto();
|
||||
});
|
||||
|
||||
await test.step('验证表格显示', async () => {
|
||||
await expect(exceptionLogPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证数据加载', async () => {
|
||||
const rowCount = await exceptionLogPage.getLogCount();
|
||||
console.log(`异常日志列表包含 ${rowCount} 条记录`);
|
||||
expect(rowCount).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('搜索异常日志', async ({ page }) => {
|
||||
await test.step('导航到异常日志页面', async () => {
|
||||
await exceptionLogPage.goto();
|
||||
});
|
||||
|
||||
await test.step('输入搜索关键词', async () => {
|
||||
const searchKeyword = 'NullPointerException';
|
||||
await exceptionLogPage.search(searchKeyword);
|
||||
});
|
||||
|
||||
await test.step('验证搜索结果', async () => {
|
||||
await page.waitForLoadState('networkidle');
|
||||
const rowCount = await exceptionLogPage.getLogCount();
|
||||
console.log(`搜索结果包含 ${rowCount} 条记录`);
|
||||
});
|
||||
});
|
||||
|
||||
test('查看异常日志详情', async ({ page }) => {
|
||||
await test.step('导航到异常日志页面', async () => {
|
||||
await exceptionLogPage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(exceptionLogPage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击查看详情按钮', async () => {
|
||||
const detailButton = page.locator('button:has-text("详情")').or(page.locator('.detail-button')).first();
|
||||
if (await detailButton.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await detailButton.click();
|
||||
|
||||
await test.step('验证详情对话框显示', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await expect(dialog).toBeVisible({ timeout: 5000 });
|
||||
console.log('异常日志详情对话框已打开');
|
||||
});
|
||||
|
||||
await test.step('关闭详情对话框', async () => {
|
||||
await exceptionLogPage.closeDetailDialog();
|
||||
});
|
||||
} else {
|
||||
console.log('当前没有异常日志记录,跳过详情查看测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('文件管理工作流', () => {
|
||||
test('文件上传流程', async ({ page }) => {
|
||||
await test.step('导航到文件管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.locator('.el-menu-item:has-text("文件管理")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('上传文件', async () => {
|
||||
const uploadButton = page.locator('button:has-text("上传")');
|
||||
if (await uploadButton.isVisible()) {
|
||||
const fileInput = page.locator('input[type="file"]');
|
||||
await fileInput.setInputFiles({
|
||||
name: 'test-file.txt',
|
||||
mimeType: 'text/plain',
|
||||
buffer: Buffer.from('Test file content'),
|
||||
});
|
||||
await page.waitForTimeout(2000);
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('验证文件上传成功', async () => {
|
||||
const successMessage = page.locator('.el-message--success');
|
||||
if (await successMessage.isVisible()) {
|
||||
expect(await successMessage.textContent()).toContain('成功');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('文件搜索和筛选', async ({ page }) => {
|
||||
await test.step('导航到文件管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.locator('text=文件管理').click();
|
||||
});
|
||||
|
||||
await test.step('搜索文件', async () => {
|
||||
const searchInput = page.locator('input[placeholder*="搜索"]');
|
||||
if (await searchInput.isVisible()) {
|
||||
await searchInput.fill('test');
|
||||
await page.locator('button:has-text("搜索")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('按类型筛选', async () => {
|
||||
const typeFilter = page.locator('.el-select:has-text("类型")');
|
||||
if (await typeFilter.isVisible()) {
|
||||
await typeFilter.click();
|
||||
await page.locator('.el-select-dropdown__item').first().click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('文件删除流程', async ({ page }) => {
|
||||
await test.step('导航到文件管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.locator('text=文件管理').click();
|
||||
});
|
||||
|
||||
await test.step('选择文件', async () => {
|
||||
const fileCheckbox = page.locator('.el-checkbox').first();
|
||||
if (await fileCheckbox.isVisible()) {
|
||||
await fileCheckbox.click();
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('删除文件', async () => {
|
||||
const deleteButton = page.locator('button:has-text("删除")');
|
||||
if (await deleteButton.isVisible()) {
|
||||
await deleteButton.click();
|
||||
await page.locator('button:has-text("确定")').click();
|
||||
await page.waitForTimeout(1000);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { NotificationPage } from '../pages/NotificationPage';
|
||||
|
||||
test.describe('通知管理工作流', () => {
|
||||
let noticePage: NotificationPage;
|
||||
const timestamp = Date.now();
|
||||
const noticeTitle = `测试通知_${timestamp}`;
|
||||
const noticeContent = `这是测试通知内容_${timestamp}`;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
noticePage = new NotificationPage(page);
|
||||
});
|
||||
|
||||
test('查看通知列表', async ({ page }) => {
|
||||
await test.step('导航到通知管理页面', async () => {
|
||||
await noticePage.goto();
|
||||
});
|
||||
|
||||
await test.step('验证表格显示', async () => {
|
||||
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证数据加载', async () => {
|
||||
const rowCount = await noticePage.getTableRowCount();
|
||||
console.log(`通知列表包含 ${rowCount} 条记录`);
|
||||
expect(rowCount).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('新增通知', async ({ page }) => {
|
||||
await test.step('导航到通知管理页面', async () => {
|
||||
await noticePage.goto();
|
||||
});
|
||||
|
||||
await test.step('点击新增通知按钮', async () => {
|
||||
await noticePage.addButton.click();
|
||||
await noticePage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写通知表单', async () => {
|
||||
await noticePage.titleInput.fill(noticeTitle);
|
||||
await noticePage.contentInput.fill(noticeContent);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await noticePage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证创建成功', async () => {
|
||||
await expect(noticePage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`通知 ${noticeTitle} 创建完成`);
|
||||
});
|
||||
});
|
||||
|
||||
test('编辑通知', async ({ page }) => {
|
||||
await test.step('导航到通知管理页面', async () => {
|
||||
await noticePage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击编辑按钮', async () => {
|
||||
const rows = await noticePage.getTableRowCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = noticePage.table.locator('tr').first();
|
||||
const editBtn = firstRow.getByRole('button', { name: '编辑' });
|
||||
if (await editBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await editBtn.click();
|
||||
await noticePage.dialog.waitFor({ state: 'visible', timeout: 5000 });
|
||||
|
||||
await test.step('修改通知内容', async () => {
|
||||
const newContent = `更新通知内容_${timestamp}`;
|
||||
await noticePage.contentInput.clear();
|
||||
await noticePage.contentInput.fill(newContent);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await noticePage.saveButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('验证更新成功', async () => {
|
||||
await expect(noticePage.dialog).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`通知已更新`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到编辑按钮,跳过编辑测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有通知记录,跳过编辑测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('删除通知', async ({ page }) => {
|
||||
await test.step('导航到通知管理页面', async () => {
|
||||
await noticePage.goto();
|
||||
});
|
||||
|
||||
await test.step('等待数据加载', async () => {
|
||||
await expect(noticePage.table).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击删除按钮', async () => {
|
||||
const rows = await noticePage.getTableRowCount();
|
||||
if (rows > 0) {
|
||||
const firstRow = noticePage.table.locator('tr').first();
|
||||
const deleteBtn = firstRow.getByRole('button', { name: '删除' });
|
||||
if (await deleteBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||||
await deleteBtn.click();
|
||||
const confirmBtn = page.locator('.el-message-box');
|
||||
await confirmBtn.waitFor({ state: 'visible', timeout: 3000 });
|
||||
|
||||
await test.step('确认删除', async () => {
|
||||
const confirmBtn = page.locator('.el-message-box').getByRole('button', { name: '确定' });
|
||||
if (await confirmBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||||
await confirmBtn.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
}
|
||||
});
|
||||
|
||||
await test.step('验证删除成功', async () => {
|
||||
const messageBox = page.locator('.el-message-box');
|
||||
await expect(messageBox).not.toBeVisible({ timeout: 5000 });
|
||||
console.log(`通知已删除`);
|
||||
});
|
||||
} else {
|
||||
console.log('未找到删除按钮,跳过删除测试');
|
||||
}
|
||||
} else {
|
||||
console.log('当前没有通知记录,跳过删除测试');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,169 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('系统配置管理完整工作流', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
const timestamp = Date.now();
|
||||
const configKey = `test_config_${timestamp}`;
|
||||
const configName = `测试配置_${timestamp}`;
|
||||
const configValue = `test_value_${timestamp}`;
|
||||
|
||||
test('创建系统配置', async ({ page }) => {
|
||||
await test.step('导航到系统配置管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=系统配置').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*configs/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('点击新增配置按钮', async () => {
|
||||
await page.locator('button:has-text("新增配置")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('填写配置信息', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(configName);
|
||||
await dialog.locator('input').nth(1).fill(configKey);
|
||||
await dialog.locator('input').nth(2).fill(configValue);
|
||||
await dialog.locator('textarea').fill(`这是测试配置的备注信息,用于验证配置管理功能。时间戳:${timestamp}`);
|
||||
});
|
||||
|
||||
await test.step('提交配置表单', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证配置已创建', async () => {
|
||||
await page.locator('input[placeholder="请输入配置名称"]').fill(configName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const configRow = page.locator(`tr:has-text("${configName}")`);
|
||||
await expect(configRow).toBeVisible({ timeout: 10000 });
|
||||
await expect(configRow.locator('td').nth(1)).toHaveText(configKey);
|
||||
await expect(configRow.locator('td').nth(2)).toHaveText(configValue);
|
||||
});
|
||||
});
|
||||
|
||||
test('编辑系统配置', async ({ page }) => {
|
||||
const updatedValue = `updated_value_${timestamp}`;
|
||||
|
||||
await test.step('导航到系统配置管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=系统配置').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('搜索并编辑配置', async () => {
|
||||
await page.locator('input[placeholder="请输入配置名称"]').fill(configName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const configRow = page.locator(`tr:has-text("${configName}")`);
|
||||
await configRow.locator('button:has-text("编辑")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('修改配置值', async () => {
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').nth(2).fill(updatedValue);
|
||||
await dialog.locator('textarea').fill(`这是更新后的配置备注,时间戳:${timestamp}`);
|
||||
});
|
||||
|
||||
await test.step('提交更新', async () => {
|
||||
await page.locator('.el-dialog button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-dialog', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证配置已更新', async () => {
|
||||
await page.locator('input[placeholder="请输入配置名称"]').fill(configName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const configRow = page.locator(`tr:has-text("${configName}")`);
|
||||
await expect(configRow.locator('td').nth(2)).toHaveText(updatedValue);
|
||||
});
|
||||
});
|
||||
|
||||
test('删除系统配置', async ({ page }) => {
|
||||
await test.step('导航到系统配置管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=系统配置').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
await test.step('搜索并删除配置', async () => {
|
||||
await page.locator('input[placeholder="请输入配置名称"]').fill(configName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const configRow = page.locator(`tr:has-text("${configName}")`);
|
||||
await configRow.locator('button:has-text("删除")').click();
|
||||
await page.waitForSelector('.el-message-box', { state: 'visible', timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('确认删除', async () => {
|
||||
await page.locator('.el-message-box button:has-text("确定")').click();
|
||||
await page.waitForSelector('.el-message-box', { state: 'hidden', timeout: 10000 });
|
||||
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('验证配置已删除', async () => {
|
||||
await page.locator('input[placeholder="请输入配置名称"]').fill(configName);
|
||||
await page.locator('button:has-text("查询")').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const emptyText = page.locator('text=暂无数据');
|
||||
await expect(emptyText).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('配置管理权限验证', async ({ page }) => {
|
||||
await test.step('验证配置管理页面访问权限', async () => {
|
||||
await page.goto('/configs');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证页面标题
|
||||
await expect(page.locator('h1:has-text("系统配置管理")')).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// 验证功能按钮可见性
|
||||
await expect(page.locator('button:has-text("新增配置")')).toBeVisible();
|
||||
await expect(page.locator('button:has-text("查询")')).toBeVisible();
|
||||
|
||||
// 验证表格列头
|
||||
await expect(page.locator('th:has-text("配置名称")')).toBeVisible();
|
||||
await expect(page.locator('th:has-text("配置键")')).toBeVisible();
|
||||
await expect(page.locator('th:has-text("配置值")')).toBeVisible();
|
||||
await expect(page.locator('th:has-text("操作")')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('验证配置搜索功能', async () => {
|
||||
const searchInput = page.locator('input[placeholder="请输入配置名称"]');
|
||||
await expect(searchInput).toBeVisible();
|
||||
|
||||
const searchButton = page.locator('button:has-text("查询")');
|
||||
await expect(searchButton).toBeVisible();
|
||||
|
||||
// 测试搜索功能
|
||||
await searchInput.fill('test');
|
||||
await searchButton.click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// 验证搜索结果
|
||||
const table = page.locator('.el-table');
|
||||
await expect(table).toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,116 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('用户权限边界验证', () => {
|
||||
test('管理员可以访问所有管理功能', async ({ page }) => {
|
||||
await test.step('验证可以访问用户管理', async () => {
|
||||
await page.goto('/users');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*users/);
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证可以访问角色管理', async () => {
|
||||
await page.goto('/roles');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*roles/);
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('验证可以访问菜单管理', async () => {
|
||||
await page.goto('/menus');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*menus/);
|
||||
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('普通用户登录后可以访问页面但API操作受限', async ({ page }) => {
|
||||
await test.step('管理员登出', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const avatarButton = page.locator('.el-avatar').first();
|
||||
await avatarButton.click({ timeout: 10000 });
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.locator('text=退出登录').click();
|
||||
await page.waitForURL(/.*login/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('普通用户登录', async () => {
|
||||
await page.goto('/login');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const usernameInput = page.locator('input[placeholder*="用户名"]');
|
||||
const passwordInput = page.locator('input[placeholder*="密码"]');
|
||||
const loginButton = page.locator('button:has-text("登录")');
|
||||
|
||||
await usernameInput.waitFor({ state: 'visible' });
|
||||
await usernameInput.fill('user');
|
||||
|
||||
await passwordInput.waitFor({ state: 'visible' });
|
||||
await passwordInput.fill('Test@123');
|
||||
|
||||
await loginButton.waitFor({ state: 'visible' });
|
||||
await loginButton.click();
|
||||
|
||||
await page.waitForURL('**/dashboard', { timeout: 30000 });
|
||||
});
|
||||
|
||||
await test.step('验证普通用户可以访问用户管理页面', async () => {
|
||||
await page.goto('/users');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(page).toHaveURL(/.*users/);
|
||||
});
|
||||
|
||||
await test.step('验证普通用户无法创建用户', async () => {
|
||||
const createButton = page.locator('button:has-text("新增用户")');
|
||||
if (await createButton.isVisible()) {
|
||||
await createButton.click();
|
||||
await page.waitForTimeout(2000);
|
||||
const errorMessage = page.locator('.el-message--error');
|
||||
const hasError = await errorMessage.isVisible().catch(() => false);
|
||||
expect(hasError || await page.locator('.el-dialog').isVisible()).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('权限不足时API返回403错误', async ({ page }) => {
|
||||
await test.step('管理员登出', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const avatarButton = page.locator('.el-avatar').first();
|
||||
await avatarButton.click({ timeout: 10000 });
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.locator('text=退出登录').click();
|
||||
await page.waitForURL(/.*login/, { timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('普通用户登录', async () => {
|
||||
await page.goto('/login');
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const usernameInput = page.locator('input[placeholder*="用户名"]');
|
||||
const passwordInput = page.locator('input[placeholder*="密码"]');
|
||||
const loginButton = page.locator('button:has-text("登录")');
|
||||
|
||||
await usernameInput.waitFor({ state: 'visible' });
|
||||
await usernameInput.fill('user');
|
||||
|
||||
await passwordInput.waitFor({ state: 'visible' });
|
||||
await passwordInput.fill('Test@123');
|
||||
|
||||
await loginButton.waitFor({ state: 'visible' });
|
||||
await loginButton.click();
|
||||
|
||||
await page.waitForURL('**/dashboard', { timeout: 30000 });
|
||||
});
|
||||
|
||||
await test.step('尝试访问受限API', async () => {
|
||||
const response = await page.request.get('/api/users?page=0&size=10');
|
||||
expect([200, 401, 403]).toContain(response.status());
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user