fix(e2e): 优化测试用例定位器和等待策略
问题: - 表单字段定位器过于复杂且不稳定 - 对话框打开/关闭缺少等待逻辑 - 菜单导航路径错误 - 页面加载等待时间不足 修复: - 简化表单字段定位器,使用索引定位 - 添加对话框状态等待(visible/hidden) - 修正菜单导航路径(系统配置 -> 参数配置/字典管理) - 增加页面加载等待和超时设置 - 统一菜单导航的等待策略 优势: - 提高测试稳定性 - 减少元素定位失败 - 确保页面完全加载后再操作 - 更清晰的测试代码结构
This commit is contained in:
@@ -13,21 +13,26 @@ test.describe('管理员完整工作流', () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('text=角色管理').click();
|
||||
await expect(page).toHaveURL(/.*roles/);
|
||||
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 () => {
|
||||
await page.locator('.el-dialog').locator('text=角色名称').locator('..').locator('input').fill(roleName);
|
||||
await page.locator('.el-dialog').locator('text=角色标识').locator('..').locator('input').fill(roleKey);
|
||||
const dialog = page.locator('.el-dialog');
|
||||
await dialog.locator('input').first().fill(roleName);
|
||||
await dialog.locator('input').nth(1).fill(roleKey);
|
||||
});
|
||||
|
||||
await test.step('提交表单', async () => {
|
||||
await page.locator('button:has-text("确定")').click();
|
||||
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 });
|
||||
});
|
||||
});
|
||||
@@ -35,25 +40,31 @@ 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 expect(page).toHaveURL(/.*users/);
|
||||
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 () => {
|
||||
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');
|
||||
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('button:has-text("确定")').click();
|
||||
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 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -64,9 +64,16 @@ test.describe('审计工作流', () => {
|
||||
test('搜索和筛选日志', async ({ page }) => {
|
||||
await test.step('导航到操作日志', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.locator('text=系统监控').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await page.locator('text=审计中心').click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.locator('text=操作日志').click();
|
||||
await expect(page.locator('table')).toBeVisible();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await expect(page.locator('table')).toBeVisible({ timeout: 10000 });
|
||||
});
|
||||
|
||||
await test.step('按模块筛选', async () => {
|
||||
|
||||
@@ -49,8 +49,12 @@ test.describe('系统配置工作流', () => {
|
||||
test('字典管理流程', async ({ page }) => {
|
||||
await test.step('导航到字典管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.locator('text=系统管理').click();
|
||||
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 () => {
|
||||
@@ -70,8 +74,12 @@ test.describe('系统配置工作流', () => {
|
||||
test('参数管理流程', async ({ page }) => {
|
||||
await test.step('导航到参数管理', async () => {
|
||||
await page.goto('/dashboard');
|
||||
await page.locator('text=系统管理').click();
|
||||
await page.locator('text=参数管理').click();
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user