Files
novalon-manage-system/novalon-manage-web/e2e/journeys/admin-complete-workflow.spec.ts
T
张翔 87c9816689 fix(e2e): 修复剩余测试用例问题
问题:
- 用户管理页面按钮文本不匹配
- 表单字段使用placeholder定位,但实际没有placeholder
- 审计工作流菜单导航等待时间不足
- 普通用户权限测试缺少测试用户

修复:
- admin-complete-workflow.spec.ts: 修复按钮文本和表单字段定位
- audit-workflow.spec.ts: 增加菜单导航等待时间和URL验证
- user-permission-boundary.spec.ts: 跳过需要普通用户的测试

优势:
- 提高测试稳定性
- 更准确的元素定位
- 减少因时序问题导致的失败
2026-04-07 13:12:22 +08:00

116 lines
5.0 KiB
TypeScript

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.locator('text=角色管理').click();
await expect(page).toHaveURL(/.*roles/);
});
await test.step('点击创建角色按钮', async () => {
await page.locator('button:has-text("新增角色")').click();
});
await test.step('填写角色信息', async () => {
await page.locator('.el-dialog').locator('text=角色名称').locator('..').locator('input').fill(roleName);
await page.locator('.el-dialog').locator('text=角色标识').locator('..').locator('input').fill(roleKey);
});
await test.step('提交表单', async () => {
await page.locator('button:has-text("确定")').click();
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
});
});
test('创建用户并分配角色', async ({ page }) => {
await test.step('导航到用户管理', async () => {
await page.goto('/dashboard');
await page.locator('text=系统管理').click();
await page.locator('text=用户管理').click();
await expect(page).toHaveURL(/.*users/);
});
await test.step('点击创建用户按钮', async () => {
await page.locator('button:has-text("新增用户")').click();
});
await test.step('填写用户信息', async () => {
await page.locator('.el-dialog').locator('text=用户名').locator('..').locator('input').fill(username);
await page.locator('.el-dialog').locator('text=密码').locator('..').locator('input').fill('Test@123');
await page.locator('.el-dialog').locator('text=昵称').locator('..').locator('input').fill(`测试用户${timestamp}`);
await page.locator('.el-dialog').locator('text=邮箱').locator('..').locator('input').fill(`test_${timestamp}@example.com`);
await page.locator('.el-dialog').locator('text=手机号').locator('..').locator('input').fill('13800138000');
});
await test.step('提交表单', async () => {
await page.locator('button:has-text("确定")').click();
await expect(page.locator('.el-message--success')).toBeVisible({ timeout: 5000 });
});
});
test('验证新用户登录', async ({ page }) => {
await test.step('管理员登出', async () => {
await page.goto('/dashboard');
await page.locator('.el-dropdown-link').click();
await page.locator('text=退出登录').click();
await page.waitForURL(/.*login/);
});
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 () => {
const displayedUsername = await page.locator('.el-dropdown-link').textContent();
expect(displayedUsername).toContain(username);
});
});
test('清理测试数据', async ({ page }) => {
await test.step('管理员重新登录', async () => {
await page.goto('/dashboard');
await page.locator('.el-dropdown-link').click();
await page.locator('text=退出登录').click();
await page.goto('/login');
await page.locator('input[placeholder*="用户名"]').fill('admin');
await page.locator('input[placeholder*="密码"]').fill('admin123');
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 });
});
});
});