fix: 修复用户管理和角色管理测试使用Page Object方法

- 修复测试2.1-2.6:用户管理测试正确使用UserManagementPage方法
- 修复测试3.1-3.5:角色管理测试正确使用RoleManagementPage方法
- 统一使用Page Object的属性和方法,避免直接操作页面元素
- 添加waitForTableReady()确保表格加载完成
- 使用submitForm()替代submitUserForm()和submitRoleForm()
- 使用search()替代searchUser()和searchRole()
- 使用containsText()检查文本存在性
This commit is contained in:
张翔
2026-04-04 09:55:18 +08:00
parent ba9cdb4b6f
commit 0e367a8873
@@ -103,9 +103,11 @@ test.describe('系统全面集成测试', () => {
test('2.1 查询用户列表', async ({ page }) => {
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
await expect(page.locator('.user-table')).toBeVisible({ timeout: 5000 });
await expect(page.locator('.user-row')).toHaveCount(await page.locator('.user-row').count());
await expect(userManagementPage.table).toBeVisible({ timeout: 5000 });
const userCount = await userManagementPage.getUserCount();
expect(userCount).toBeGreaterThan(0);
});
test('2.2 创建新用户', async ({ page }) => {
@@ -113,6 +115,7 @@ test.describe('系统全面集成测试', () => {
const username = `testuser_${timestamp}`;
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
await userManagementPage.clickCreateUser();
await userManagementPage.fillUserForm({
username: username,
@@ -121,25 +124,27 @@ test.describe('系统全面集成测试', () => {
phone: '13800138000',
nickname: `测试用户${timestamp}`
});
await userManagementPage.submitUserForm();
await userManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
await userManagementPage.searchUser(username);
await expect(page.locator('.user-row').first()).toContainText(username);
await userManagementPage.search(username);
await page.waitForTimeout(1000);
const found = await userManagementPage.containsText(username);
expect(found).toBeTruthy();
});
test('2.3 编辑用户信息', async ({ page }) => {
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
const firstUser = page.locator('.user-row').first();
await firstUser.locator('[data-testid="edit-button"]').click();
await userManagementPage.clickEditButton(1);
const newNickname = `更新昵称_${Date.now()}`;
await page.fill('[name="nickname"]', newNickname);
await page.click('[data-testid="submit-button"]');
await userManagementPage.fillNickname(newNickname);
await userManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
test('2.4 删除用户', async ({ page }) => {
@@ -147,6 +152,7 @@ test.describe('系统全面集成测试', () => {
const username = `deleteuser_${timestamp}`;
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
await userManagementPage.clickCreateUser();
await userManagementPage.fillUserForm({
username: username,
@@ -155,45 +161,36 @@ test.describe('系统全面集成测试', () => {
phone: '13800138000',
nickname: `待删除用户${timestamp}`
});
await userManagementPage.submitUserForm();
await userManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
await userManagementPage.searchUser(username);
const userRow = page.locator('.user-row').first();
await userRow.locator('[data-testid="delete-button"]').click();
await userManagementPage.search(username);
await page.waitForTimeout(1000);
await userManagementPage.clickDeleteButton(1);
await userManagementPage.confirmDelete();
page.on('dialog', dialog => dialog.accept());
await page.click('[data-testid="confirm-delete-button"]');
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
test('2.5 分配用户角色', async ({ page }) => {
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
const firstUser = page.locator('.user-row').first();
await firstUser.locator('[data-testid="assign-role-button"]').click();
await userManagementPage.clickEditButton(1);
await userManagementPage.selectRole('管理员');
await userManagementPage.submitForm();
await page.check('[data-testid="role-admin"]');
await page.click('[data-testid="submit-button"]');
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
test('2.6 启用/禁用用户', async ({ page }) => {
await userManagementPage.goto();
await userManagementPage.waitForTableReady();
const firstUser = page.locator('.user-row').first();
const statusButton = firstUser.locator('[data-testid="toggle-status-button"]');
const currentStatus = await statusButton.getAttribute('data-status');
await userManagementPage.clickStatusButton(1);
await statusButton.click();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
const newStatus = await statusButton.getAttribute('data-status');
expect(newStatus).not.toBe(currentStatus);
await expect(userManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
});
@@ -206,9 +203,10 @@ test.describe('系统全面集成测试', () => {
test('3.1 查询角色列表', async ({ page }) => {
await roleManagementPage.goto();
await roleManagementPage.waitForTableReady();
await expect(page.locator('.role-table')).toBeVisible({ timeout: 5000 });
const roleCount = await page.locator('.role-row').count();
await expect(roleManagementPage.table).toBeVisible({ timeout: 5000 });
const roleCount = await roleManagementPage.table.locator('tbody tr').count();
expect(roleCount).toBeGreaterThan(0);
});
@@ -218,31 +216,34 @@ test.describe('系统全面集成测试', () => {
const roleKey = `test_role_${timestamp}`;
await roleManagementPage.goto();
await roleManagementPage.waitForTableReady();
await roleManagementPage.clickCreateRole();
await roleManagementPage.fillRoleForm({
roleName: roleName,
roleKey: roleKey,
roleSort: '99'
});
await roleManagementPage.submitRoleForm();
await roleManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(roleManagementPage.successMessage).toBeVisible({ timeout: 5000 });
await roleManagementPage.searchRole(roleName);
await expect(page.locator('.role-row').first()).toContainText(roleName);
await roleManagementPage.search(roleName);
await page.waitForTimeout(1000);
const found = await roleManagementPage.containsText(roleName);
expect(found).toBeTruthy();
});
test('3.3 编辑角色', async ({ page }) => {
await roleManagementPage.goto();
await roleManagementPage.waitForTableReady();
const firstRole = page.locator('.role-row').first();
await firstRole.locator('[data-testid="edit-button"]').click();
await roleManagementPage.editRole(1);
const newRoleName = `更新角色_${Date.now()}`;
await page.fill('[name="roleName"]', newRoleName);
await page.click('[data-testid="submit-button"]');
await page.locator('.el-dialog').locator('input').first().fill(newRoleName);
await roleManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(roleManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
test('3.4 删除角色', async ({ page }) => {
@@ -251,36 +252,35 @@ test.describe('系统全面集成测试', () => {
const roleKey = `delete_role_${timestamp}`;
await roleManagementPage.goto();
await roleManagementPage.waitForTableReady();
await roleManagementPage.clickCreateRole();
await roleManagementPage.fillRoleForm({
roleName: roleName,
roleKey: roleKey,
roleSort: '99'
});
await roleManagementPage.submitRoleForm();
await roleManagementPage.submitForm();
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(roleManagementPage.successMessage).toBeVisible({ timeout: 5000 });
await roleManagementPage.searchRole(roleName);
const roleRow = page.locator('.role-row').first();
await roleRow.locator('[data-testid="delete-button"]').click();
await roleManagementPage.search(roleName);
await page.waitForTimeout(1000);
await roleManagementPage.deleteRole(1);
await roleManagementPage.confirmDelete();
page.on('dialog', dialog => dialog.accept());
await page.click('[data-testid="confirm-delete-button"]');
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(roleManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
test('3.5 分配角色权限', async ({ page }) => {
await roleManagementPage.goto();
await roleManagementPage.waitForTableReady();
const firstRole = page.locator('.role-row').first();
await firstRole.locator('[data-testid="assign-permission-button"]').click();
await roleManagementPage.clickPermissionButton(1);
await page.waitForTimeout(500);
await roleManagementPage.selectPermission('user:manage');
await roleManagementPage.savePermissions();
await page.check('[data-testid="permission-user-manage"]');
await page.click('[data-testid="submit-button"]');
await expect(page.locator('.success-message')).toBeVisible({ timeout: 5000 });
await expect(roleManagementPage.successMessage).toBeVisible({ timeout: 5000 });
});
});