fix: optimize UserManagementPage navigation with better error handling

This commit is contained in:
张翔
2026-04-04 09:02:28 +08:00
parent f48db8f094
commit 3177ebdd7a
@@ -1,4 +1,4 @@
import { Page, Locator } from '@playwright/test';
import { Page, Locator, expect } from '@playwright/test';
export class UserManagementPage {
readonly page: Page;
@@ -24,8 +24,38 @@ export class UserManagementPage {
}
async goto() {
await this.page.goto('/users');
await this.page.waitForLoadState('networkidle');
try {
console.log('导航到用户管理页面...');
await this.page.goto('/users');
await this.page.waitForLoadState('networkidle');
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await expect(this.page).toHaveURL(/.*users/);
console.log('用户管理页面加载完成');
} catch (error) {
await this.page.screenshot({ path: `test-results/user-management-error-${Date.now()}.png` });
console.error('导航到用户管理页面失败:', error);
throw new Error(`导航到用户管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
}
}
async waitForTableReady() {
await this.table.waitFor({ state: 'visible', timeout: 10000 });
await this.page.waitForFunction(
() => {
const rows = document.querySelectorAll('.el-table__body-wrapper tbody tr');
return rows.length > 0;
},
{ timeout: 5000 }
).catch(() => {
console.log('表格没有数据,继续执行');
});
}
async clickCreateUser() {