fix: 修复E2E测试选择器和等待策略

问题分析:
1. 错误消息使用ElMessage toast,测试期望页面文本
2. 登出下拉菜单选择器不够精确
3. 用户管理页面按钮文本不匹配
4. 缺少适当的等待策略

修复内容:
- 登录流程测试:检测.el-message--error toast消息
- 表单验证测试:触发blur事件后检测.el-form-item__error
- 登出流程测试:使用更精确的下拉菜单选择器
- 用户管理测试:修正按钮文本为'新增用户'
- 添加waitForLoadState确保页面加载完成
- 增加timeout参数提高测试稳定性
This commit is contained in:
张翔
2026-04-04 22:43:15 +08:00
parent f2dde38467
commit 977e283fbd
3 changed files with 28 additions and 18 deletions
@@ -25,23 +25,25 @@ test.describe('权限边界验证测试', () => {
test('管理员可以创建用户', async ({ page }) => {
await page.goto('/users');
const createButton = page.locator('button:has-text("新增")');
const createButton = page.locator('button:has-text("新增用户")');
await expect(createButton).toBeVisible();
await expect(createButton).toBeEnabled();
});
test('管理员可以编辑用户', async ({ page }) => {
await page.goto('/users');
await page.waitForLoadState('networkidle');
const editButton = page.locator('button:has-text("编辑")').first();
await expect(editButton).toBeVisible();
await expect(editButton).toBeVisible({ timeout: 5000 });
});
test('管理员可以删除用户', async ({ page }) => {
await page.goto('/users');
await page.waitForLoadState('networkidle');
const deleteButton = page.locator('button:has-text("删除")').first();
await expect(deleteButton).toBeVisible();
await expect(deleteButton).toBeVisible({ timeout: 5000 });
});
});