|
|
@@ -20,16 +20,15 @@ export class UserManagementPage {
|
|
|
this.userTable = page.locator('table');
|
|
|
this.editButtons = page.locator('button').filter({ hasText: '编辑' });
|
|
|
this.deleteButtons = page.locator('button').filter({ hasText: '删除' });
|
|
|
- this.pagination = page.locator('[data-testid="pagination"]');
|
|
|
+ this.pagination = page.locator('[data-slot="pagination"]');
|
|
|
}
|
|
|
|
|
|
async goto() {
|
|
|
// 直接导航到用户管理页面
|
|
|
await this.page.goto('/admin/users');
|
|
|
- await this.page.waitForLoadState('networkidle');
|
|
|
|
|
|
- // 等待页面完全加载
|
|
|
- await this.page.waitForTimeout(5000);
|
|
|
+ // 等待页面完全加载 - 使用更可靠的等待条件
|
|
|
+ await this.page.waitForLoadState('networkidle');
|
|
|
await this.expectToBeVisible();
|
|
|
}
|
|
|
|
|
|
@@ -78,14 +77,32 @@ export class UserManagementPage {
|
|
|
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();
|
|
|
+ // 等待用户创建结果提示 - 成功或失败
|
|
|
+ try {
|
|
|
+ await Promise.race([
|
|
|
+ this.page.waitForSelector('text=创建成功', { timeout: 10000 }),
|
|
|
+ this.page.waitForSelector('text=创建失败', { timeout: 10000 })
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 检查是否有错误提示
|
|
|
+ const errorVisible = await this.page.locator('text=创建失败').isVisible().catch(() => false);
|
|
|
+ if (errorVisible) {
|
|
|
+ // 如果是创建失败,不需要刷新页面
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是创建成功,刷新页面
|
|
|
+ await this.page.waitForTimeout(1000);
|
|
|
+ await this.page.reload();
|
|
|
+ await this.page.waitForLoadState('networkidle');
|
|
|
+ await this.expectToBeVisible();
|
|
|
+ } catch (error) {
|
|
|
+ // 如果没有提示出现,继续执行
|
|
|
+ console.log('创建操作没有显示提示信息,继续执行');
|
|
|
+ await this.page.reload();
|
|
|
+ await this.page.waitForLoadState('networkidle');
|
|
|
+ await this.expectToBeVisible();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async getUserCount(): Promise<number> {
|
|
|
@@ -154,13 +171,22 @@ export class UserManagementPage {
|
|
|
// 确认删除对话框
|
|
|
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('删除操作失败:前端显示删除失败提示');
|
|
|
+ // 等待删除操作完成 - 等待成功提示或错误提示
|
|
|
+ try {
|
|
|
+ // 等待成功提示或错误提示出现
|
|
|
+ await Promise.race([
|
|
|
+ this.page.waitForSelector('text=删除成功', { timeout: 10000 }),
|
|
|
+ this.page.waitForSelector('text=删除失败', { timeout: 10000 })
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 检查是否有错误提示
|
|
|
+ const errorVisible = await this.page.locator('text=删除失败').isVisible().catch(() => false);
|
|
|
+ if (errorVisible) {
|
|
|
+ throw new Error('删除操作失败:前端显示删除失败提示');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ // 如果没有提示出现,继续执行(可能是静默删除)
|
|
|
+ console.log('删除操作没有显示提示信息,继续执行');
|
|
|
}
|
|
|
|
|
|
// 刷新页面确认用户是否被删除
|