第一次

This commit is contained in:
dengqichen 2025-03-06 09:41:20 +08:00
parent 5e1d37134e
commit 54296d639a

View File

@ -76,8 +76,6 @@ class LongiMainPage extends BasePage {
/**
* 检查并展开侧边菜单
* 如果菜单已收起则点击展开
* @returns {Promise<boolean>} 是否执行了展开操作
*/
async expandSideMenu() {
// 检查菜单是否已展开
@ -86,10 +84,7 @@ class LongiMainPage extends BasePage {
if (!isExpanded) {
console.log('菜单未展开,点击展开');
await this.clickExpandMenu();
return true;
}
return false;
}
/**
@ -255,7 +250,7 @@ class LongiMainPage extends BasePage {
}
} catch (error) {
console.error('处理菜单点击时出错:', error);
throw error; // 向上传播错误
throw error;
}
}
@ -442,9 +437,9 @@ class LongiMainPage extends BasePage {
// 1. 点击菜单并等待页面加载
await menuInfo.element.click();
const loadResult = await this.waitForPageLoadWithRetry(menuInfo);
const isLoaded = await this.waitForPageLoadWithRetry(menuInfo);
if (!loadResult) {
if (!isLoaded) {
console.warn(`页面加载失败: ${menuPath}`);
return;
}
@ -458,18 +453,16 @@ class LongiMainPage extends BasePage {
/**
* 处理单个TAB页
* @param {Object} tabInfo TAB页信息对象包含textisActive和element属性
* @param {Object} tabInfo TAB页信息对象
* @param {Object} parentMenu 父级菜单对象
* @private
*/
async handleSingleTab(tabInfo, parentMenu) {
try {
const menuPath = parentMenu.path || parentMenu.text;
console.log(`🔹 处理TAB页: ${menuPath} > ${tabInfo.text}`);
// 直接使用传入的element点击
await tabInfo.element.click();
await this.waitForPageLoadWithRetry(parentMenu, tabInfo.text)
await this.waitForPageLoadWithRetry(parentMenu, tabInfo.text);
} catch (error) {
console.error(`处理TAB页失败 [${parentMenu.text} > ${tabInfo.text}]:`, error.message);
}
@ -478,7 +471,6 @@ class LongiMainPage extends BasePage {
/**
* 处理所有TAB页
* @param {Object} menu 菜单对象
* @private
*/
async handleAllTabs(menu) {
try {
@ -494,25 +486,23 @@ class LongiMainPage extends BasePage {
console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`);
// 获取所有TAB页的完整信息(文本、激活状态和元素引用)
// 获取所有TAB页的完整信息
const tabInfos = await Promise.all(
tabs.map(async element => ({
text: (await element.textContent()).trim(),
isActive: await element.evaluate(el => el.classList.contains('is-active')),
element: element // 保存元素引用
element: element
}))
);
// 处理每个非激活的TAB页
for (const tabInfo of tabInfos) {
// 跳过当前激活的TAB页因为它已经是默认加载的
if (!tabInfo.isActive) {
await this.handleSingleTab(tabInfo, menu);
} else {
console.log(`⏭️ 跳过当前激活的TAB页: ${menu.text} > ${tabInfo.text}`);
}
}
} catch (error) {
console.error(`处理TAB页失败 [${menu.text}]:`, error.message);
}
@ -583,12 +573,11 @@ class LongiMainPage extends BasePage {
/**
* 关闭当前活动的标签页
* @param {string} pageName 页面名称用于日志显示
* @returns {Promise<boolean>} 是否成功关闭标签页
*/
async closeActiveTab(pageName) {
try {
console.log(`🗑️ 正在关闭页面 "${pageName}" 的tab...`);
// 检查是否存在活动的tab和关闭按钮
const activeTab = this.page.locator('.vab-tabs .el-tabs--card .el-tabs__item.is-active');
const closeButton = activeTab.locator('.el-icon.is-icon-close');
@ -596,20 +585,14 @@ class LongiMainPage extends BasePage {
const hasCloseButton = await closeButton.count() > 0;
if (hasActiveTab && hasCloseButton) {
// 确保关闭按钮可见并点击
await closeButton.waitFor({state: 'visible', timeout: 5000});
await closeButton.click();
// 等待关闭动画完成
await this.page.waitForTimeout(500);
return true;
} else {
console.log(`⚠️ [${pageName}] 没有找到可关闭的tab继续执行...`);
return false;
}
} catch (error) {
console.error(`关闭标签页时出错 [${pageName}]:`, error.message);
return false;
}
}
}