|
|
@@ -74,9 +74,18 @@ export class UserManagementPage {
|
|
|
await this.page.getByLabel('真实姓名').fill(userData.name);
|
|
|
}
|
|
|
|
|
|
- // 提交表单
|
|
|
- await this.page.getByRole('button', { name: '创建用户' }).click();
|
|
|
+ // 提交表单 - 使用模态框中的创建按钮
|
|
|
+ await this.page.locator('[role="dialog"]').getByRole('button', { name: '创建用户' }).click();
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
+
|
|
|
+ // 等待用户创建成功提示
|
|
|
+ await this.page.waitForSelector('text=创建成功', { timeout: 10000 });
|
|
|
+
|
|
|
+ // 等待页面自动刷新或手动刷新
|
|
|
+ await this.page.waitForTimeout(1000);
|
|
|
+ await this.page.reload();
|
|
|
+ await this.page.waitForLoadState('networkidle');
|
|
|
+ await this.expectToBeVisible();
|
|
|
}
|
|
|
|
|
|
async getUserCount(): Promise<number> {
|
|
|
@@ -89,6 +98,11 @@ export class UserManagementPage {
|
|
|
return (await userRow.count()) > 0 ? userRow : null;
|
|
|
}
|
|
|
|
|
|
+ async userExists(username: string): Promise<boolean> {
|
|
|
+ const userRow = this.userTable.locator('tbody tr').filter({ hasText: username }).first();
|
|
|
+ return (await userRow.count()) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
async editUser(username: string, updates: {
|
|
|
nickname?: string;
|
|
|
email?: string;
|
|
|
@@ -98,7 +112,13 @@ export class UserManagementPage {
|
|
|
const userRow = await this.getUserByUsername(username);
|
|
|
if (!userRow) throw new Error(`User ${username} not found`);
|
|
|
|
|
|
- await userRow.locator('button').filter({ hasText: '编辑' }).click();
|
|
|
+ // 编辑按钮是图标按钮,使用按钮定位(第一个按钮是编辑,第二个是删除)
|
|
|
+ const editButton = userRow.locator('button').first();
|
|
|
+ await editButton.waitFor({ state: 'visible', timeout: 10000 });
|
|
|
+ await editButton.click();
|
|
|
+
|
|
|
+ // 等待编辑模态框出现
|
|
|
+ await this.page.waitForSelector('[role="dialog"]', { state: 'visible', timeout: 10000 });
|
|
|
|
|
|
// 更新字段
|
|
|
if (updates.nickname) {
|
|
|
@@ -115,26 +135,47 @@ export class UserManagementPage {
|
|
|
}
|
|
|
|
|
|
// 提交更新
|
|
|
- await this.page.getByRole('button', { name: '更新用户' }).click();
|
|
|
+ await this.page.locator('[role="dialog"]').getByRole('button', { name: '更新用户' }).click();
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
+
|
|
|
+ // 等待操作完成
|
|
|
+ await this.page.waitForTimeout(1000);
|
|
|
}
|
|
|
|
|
|
async deleteUser(username: string) {
|
|
|
const userRow = await this.getUserByUsername(username);
|
|
|
if (!userRow) throw new Error(`User ${username} not found`);
|
|
|
|
|
|
- await userRow.locator('button').filter({ hasText: '删除' }).click();
|
|
|
+ // 删除按钮是图标按钮,使用按钮定位(第二个按钮是删除)
|
|
|
+ const deleteButton = userRow.locator('button').nth(1);
|
|
|
+ await deleteButton.waitFor({ state: 'visible', timeout: 10000 });
|
|
|
+ await deleteButton.click();
|
|
|
+
|
|
|
+ // 确认删除对话框
|
|
|
await this.page.getByRole('button', { name: '删除' }).click();
|
|
|
+
|
|
|
+ // 等待删除操作完成
|
|
|
+ await this.page.waitForTimeout(2000);
|
|
|
+
|
|
|
+ // 检查是否有错误提示
|
|
|
+ const errorVisible = await this.page.locator('text=删除失败').isVisible().catch(() => false);
|
|
|
+ if (errorVisible) {
|
|
|
+ throw new Error('删除操作失败:前端显示删除失败提示');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 刷新页面确认用户是否被删除
|
|
|
+ await this.page.reload();
|
|
|
await this.page.waitForLoadState('networkidle');
|
|
|
+ await this.expectToBeVisible();
|
|
|
}
|
|
|
|
|
|
async expectUserExists(username: string) {
|
|
|
- const userRow = await this.getUserByUsername(username);
|
|
|
- await expect(userRow).not.toBeNull();
|
|
|
+ const exists = await this.userExists(username);
|
|
|
+ expect(exists).toBe(true);
|
|
|
}
|
|
|
|
|
|
async expectUserNotExists(username: string) {
|
|
|
- const userRow = await this.getUserByUsername(username);
|
|
|
- await expect(userRow).toBeNull();
|
|
|
+ const exists = await this.userExists(username);
|
|
|
+ expect(exists).toBe(false);
|
|
|
}
|
|
|
}
|