test: 删除journeys目录下的重复测试文件(任务 4/8)

This commit is contained in:
张翔
2026-04-07 21:47:53 +08:00
parent 105ad30cc6
commit 39174f09d2
2 changed files with 0 additions and 297 deletions
@@ -1,197 +0,0 @@
import { test, expect } from '@playwright/test';
test.describe('权限边界测试', () => {
test.describe.configure({ mode: 'serial' });
const timestamp = Date.now();
const normalUsername = `normal_user_${timestamp}`;
const normalPassword = 'Test@123';
test('准备:创建普通用户', async ({ page }) => {
await test.step('管理员登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', 'admin');
await page.fill('input[type="password"]', 'Test@123');
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
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 });
const dialog = page.locator('.el-dialog');
await dialog.locator('input').first().fill(normalUsername);
await dialog.locator('input[type="password"]').fill(normalPassword);
await dialog.locator('input').nth(2).fill(`普通用户${timestamp}`);
await dialog.locator('input').nth(3).fill(`normal_${timestamp}@example.com`);
await dialog.locator('input').nth(4).fill('13800138001');
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.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const userRow = page.locator(`tr:has-text("${normalUsername}")`);
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 availableRole = transfer.locator('.el-transfer-panel').first().locator('.el-checkbox:has-text("普通用户")');
if (await availableRole.isVisible()) {
await availableRole.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')).toBeVisible({ timeout: 5000 });
});
await test.step('管理员登出', async () => {
await page.locator('.el-dropdown-link').click();
await page.waitForTimeout(500);
await page.locator('text=退出登录').click();
await page.waitForURL(/.*login/, { timeout: 10000 });
});
});
test('普通用户登录', async ({ page }) => {
await test.step('普通用户登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', normalUsername);
await page.fill('input[type="password"]', normalPassword);
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
await test.step('验证登录成功', async () => {
await expect(page.locator('text=仪表盘')).toBeVisible({ timeout: 5000 });
});
});
test('普通用户不能访问用户管理页面', async ({ page }) => {
await test.step('普通用户登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', normalUsername);
await page.fill('input[type="password"]', normalPassword);
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
await test.step('尝试直接访问用户管理页面', async () => {
await page.goto('/dashboard/system/users');
await page.waitForLoadState('networkidle');
});
await test.step('验证被重定向或显示无权限提示', async () => {
const currentUrl = page.url();
const hasNoPermission = await page.locator('text=无权限').isVisible().catch(() => false);
const isRedirected = !currentUrl.includes('/users');
expect(hasNoPermission || isRedirected).toBeTruthy();
});
});
test('普通用户不能访问角色管理页面', async ({ page }) => {
await test.step('普通用户登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', normalUsername);
await page.fill('input[type="password"]', normalPassword);
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
await test.step('尝试直接访问角色管理页面', async () => {
await page.goto('/dashboard/system/roles');
await page.waitForLoadState('networkidle');
});
await test.step('验证被重定向或显示无权限提示', async () => {
const currentUrl = page.url();
const hasNoPermission = await page.locator('text=无权限').isVisible().catch(() => false);
const isRedirected = !currentUrl.includes('/roles');
expect(hasNoPermission || isRedirected).toBeTruthy();
});
});
test('普通用户不能创建用户', async ({ page }) => {
await test.step('普通用户登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', normalUsername);
await page.fill('input[type="password"]', normalPassword);
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
await test.step('尝试通过API创建用户', async () => {
const response = await page.request.post('http://localhost:8084/api/users', {
headers: {
'Content-Type': 'application/json',
},
data: {
username: `unauthorized_user_${Date.now()}`,
password: 'Test@123',
nickname: '未授权用户',
email: `unauthorized_${Date.now()}@example.com`,
phone: '13800138002',
},
});
expect(response.status()).toBe(401);
});
});
test('清理:删除测试用户', async ({ page }) => {
await test.step('管理员登录', async () => {
await page.goto('/login');
await page.fill('input[type="text"]', 'admin');
await page.fill('input[type="password"]', 'Test@123');
await page.click('button:has-text("登录")');
await page.waitForURL(/.*dashboard/, { timeout: 10000 });
});
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.reload();
await page.waitForLoadState('networkidle');
await page.waitForTimeout(1000);
const userRow = page.locator(`tr:has-text("${normalUsername}")`);
if (await userRow.isVisible()) {
await userRow.locator('button:has-text("删除")').click();
await page.waitForSelector('.el-message-box', { state: 'visible', timeout: 5000 });
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 });
}
});
});
});
@@ -1,100 +0,0 @@
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('text=参数配置').click();
await page.waitForLoadState('networkidle');
await expect(page).toHaveURL(/.*sys\/config/, { timeout: 10000 });
});
await test.step('验证配置列表显示', async () => {
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
});
});
test('修改系统配置', async ({ page }) => {
await test.step('导航到系统配置', async () => {
await page.goto('/sys/config');
});
await test.step('点击编辑按钮', async () => {
const editButton = page.locator('button:has-text("编辑")').first();
if (await editButton.isVisible()) {
await editButton.click();
}
});
await test.step('修改配置值', async () => {
const configInput = page.locator('input').first();
if (await configInput.isVisible()) {
const currentValue = await configInput.inputValue();
await configInput.fill(currentValue);
}
});
await test.step('保存配置', async () => {
const saveButton = page.locator('button:has-text("保存")');
if (await saveButton.isVisible()) {
await saveButton.click();
await page.waitForTimeout(1000);
}
});
});
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(/.*dict/, { timeout: 10000 });
});
await test.step('查看字典列表', async () => {
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
});
await test.step('搜索字典项', async () => {
const searchInput = page.locator('input[placeholder*="搜索"]');
if (await searchInput.isVisible()) {
await searchInput.fill('status');
await page.locator('button:has-text("搜索")').click();
await page.waitForTimeout(1000);
}
});
});
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(/.*sys\/config/, { timeout: 10000 });
});
await test.step('查看参数列表', async () => {
await expect(page.locator('.el-table')).toBeVisible({ timeout: 10000 });
});
await test.step('添加新参数', async () => {
const addButton = page.locator('button:has-text("新建")');
if (await addButton.isVisible()) {
await addButton.click();
await page.locator('input[placeholder*="参数名"]').fill('test_param');
await page.locator('input[placeholder*="参数值"]').fill('test_value');
await page.locator('button:has-text("确定")').click();
await page.waitForTimeout(1000);
}
});
});
});