fix: optimize all Page Object navigation with better error handling
- MenuManagementPage: add tree/table wait and error handling - SystemConfigPage: add table wait and error handling - DictionaryManagementPage: add table wait and error handling - FileManagementPage: add table wait and error handling - OperationLogPage: add table wait and error handling - LoginLogPage: add table wait and error handling - ExceptionLogPage: add table wait and 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 DictionaryManagementPage {
|
||||
readonly page: Page;
|
||||
@@ -24,8 +24,20 @@ export class DictionaryManagementPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/dict');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到字典管理页面...');
|
||||
await this.page.goto('/dict');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*dict/);
|
||||
|
||||
console.log('字典管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/dict-management-error-${Date.now()}.png` });
|
||||
console.error('导航到字典管理页面失败:', error);
|
||||
throw new Error(`导航到字典管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async clickCreateDictType() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class ExceptionLogPage {
|
||||
readonly page: Page;
|
||||
@@ -22,8 +22,20 @@ export class ExceptionLogPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/exceptionlog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到异常日志页面...');
|
||||
await this.page.goto('/exceptionlog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*exceptionlog/);
|
||||
|
||||
console.log('异常日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/exception-log-error-${Date.now()}.png` });
|
||||
console.error('导航到异常日志页面失败:', error);
|
||||
throw new Error(`导航到异常日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async search(keyword: string) {
|
||||
|
||||
@@ -20,9 +20,20 @@ export class FileManagementPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/files');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.page.waitForTimeout(3000);
|
||||
try {
|
||||
console.log('导航到文件管理页面...');
|
||||
await this.page.goto('/files');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*files/);
|
||||
|
||||
console.log('文件管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/file-management-error-${Date.now()}.png` });
|
||||
console.error('导航到文件管理页面失败:', error);
|
||||
throw new Error(`导航到文件管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async uploadFile(filePath: string) {
|
||||
|
||||
@@ -16,8 +16,20 @@ export class LoginLogPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/loginlog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到登录日志页面...');
|
||||
await this.page.goto('/loginlog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*loginlog/);
|
||||
|
||||
console.log('登录日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/login-log-error-${Date.now()}.png` });
|
||||
console.error('导航到登录日志页面失败:', error);
|
||||
throw new Error(`导航到登录日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Page, Locator } from '@playwright/test';
|
||||
import { Page, Locator, expect } from '@playwright/test';
|
||||
|
||||
export class MenuManagementPage {
|
||||
readonly page: Page;
|
||||
@@ -24,8 +24,24 @@ export class MenuManagementPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/menus');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到菜单管理页面...');
|
||||
await this.page.goto('/menus');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
|
||||
await this.page.waitForSelector('.el-tree', { timeout: 10000 }).catch(() => {
|
||||
return this.page.waitForSelector('.el-table', { timeout: 5000 });
|
||||
});
|
||||
|
||||
await expect(this.page).toHaveURL(/.*menus/);
|
||||
|
||||
console.log('菜单管理页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/menu-management-error-${Date.now()}.png` });
|
||||
console.error('导航到菜单管理页面失败:', error);
|
||||
throw new Error(`导航到菜单管理页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async clickCreateMenu() {
|
||||
|
||||
@@ -16,8 +16,20 @@ export class OperationLogPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/oplog');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到操作日志页面...');
|
||||
await this.page.goto('/oplog');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*oplog/);
|
||||
|
||||
console.log('操作日志页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/operation-log-error-${Date.now()}.png` });
|
||||
console.error('导航到操作日志页面失败:', error);
|
||||
throw new Error(`导航到操作日志页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async searchByKeyword(keyword: string) {
|
||||
|
||||
@@ -32,8 +32,20 @@ export class SystemConfigPage {
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/sys/config');
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
try {
|
||||
console.log('导航到系统配置页面...');
|
||||
await this.page.goto('/sys/config');
|
||||
|
||||
await this.page.waitForLoadState('networkidle');
|
||||
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
||||
await expect(this.page).toHaveURL(/.*config/);
|
||||
|
||||
console.log('系统配置页面加载完成');
|
||||
} catch (error) {
|
||||
await this.page.screenshot({ path: `test-results/system-config-error-${Date.now()}.png` });
|
||||
console.error('导航到系统配置页面失败:', error);
|
||||
throw new Error(`导航到系统配置页面失败: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async addConfig(configName: string, configKey: string, configValue: string, configType: string = 'Y') {
|
||||
|
||||
Reference in New Issue
Block a user