fix: optimize RoleManagementPage navigation with better error handling
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Page, Locator } from '@playwright/test';
|
import { Page, Locator, expect } from '@playwright/test';
|
||||||
|
|
||||||
export class RoleManagementPage {
|
export class RoleManagementPage {
|
||||||
readonly page: Page;
|
readonly page: Page;
|
||||||
@@ -38,8 +38,34 @@ export class RoleManagementPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async goto() {
|
async goto() {
|
||||||
await this.page.goto('/roles');
|
try {
|
||||||
await this.page.waitForLoadState('networkidle');
|
console.log('导航到角色管理页面...');
|
||||||
|
await this.page.goto('/roles');
|
||||||
|
|
||||||
|
await this.page.waitForLoadState('networkidle');
|
||||||
|
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||||
|
await expect(this.page).toHaveURL(/.*roles/);
|
||||||
|
|
||||||
|
console.log('角色管理页面加载完成');
|
||||||
|
} catch (error) {
|
||||||
|
await this.page.screenshot({ path: `test-results/role-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 clickCreateRole() {
|
async clickCreateRole() {
|
||||||
|
|||||||
Reference in New Issue
Block a user