优化分批执行点击菜单

This commit is contained in:
dengqichen 2025-03-07 18:30:26 +08:00
parent 2f6456f027
commit e7798329a2

View File

@ -35,7 +35,9 @@ class LongiMainPage extends BasePage {
// Tab相关 // Tab相关
tabContainer: '.workSpaceBaseTab .el-tabs__item', tabContainer: '.workSpaceBaseTab .el-tabs__item',
activeTab: '.vab-tabs .el-tabs--card .el-tabs__item.is-active', activeTab: '.vab-tabs .el-tabs--card .el-tabs__item.is-active',
closeButton: '.el-icon.is-icon-close' closeButton: '.el-icon.is-icon-close',
tabItems: '.workSpaceBaseTab .el-tabs__item',
nextTabButton: '.el-icon.is-icon-next'
}); });
} }
@ -380,19 +382,30 @@ class LongiMainPage extends BasePage {
} }
/** /**
* 处理单个TAB页 * 查找标签页信息
* @param {Object} tabInfo TAB页信息对象 * @param {Object} menu 菜单对象
* @param {Object} parentMenu 父级菜单对象 * @returns {Promise<Array>} 标签页信息数组
* @private
*/ */
async handleSingleTab(tabInfo, parentMenu) { async findTabInfos(menu) {
try { const tabs = await this.page.locator(this.selectors.tabContainer).all();
const menuPath = parentMenu.path || parentMenu.text; if (tabs.length === 0) {
const tabPath = `${menuPath} > ${tabInfo.text}`; console.log(`📝 ${menu.text} 没有TAB页`);
await tabInfo.element.click(); return [];
await this.waitForIBPPageLoadWithRetry(tabPath);
} catch (error) {
console.error(`处理TAB页失败 [${parentMenu.text} > ${tabInfo.text}]:`, error.message);
} }
console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`);
const tabInfos = [];
for (const tab of tabs) {
const text = await tab.textContent();
const isActive = await tab.evaluate(el => el.classList.contains('is-active'));
tabInfos.push({
text: text.trim(),
element: tab,
isActive: isActive
});
}
return tabInfos;
} }
/** /**
@ -403,21 +416,19 @@ class LongiMainPage extends BasePage {
try { try {
await this.waitForTimeout(1000); await this.waitForTimeout(1000);
const tabs = await this.page.locator(this.selectors.tabContainer).all(); const tabInfos = await this.findTabInfos(menu);
if (tabs.length === 0) { if (tabInfos.length === 0) {
console.log(`📝 ${menu.text} 没有TAB页`);
return; return;
} }
console.log(`📑 ${menu.text} 找到 ${tabs.length} 个TAB页`); let hasSkippedActiveTab = false;
const tabInfos = await this.findTabInfos(tabs);
for (const tabInfo of tabInfos) { for (const tabInfo of tabInfos) {
if (!tabInfo.isActive) { if (tabInfo.isActive && !hasSkippedActiveTab) {
await this.handleSingleTab(tabInfo, menu);
} else {
console.log(`⏭️ 跳过当前激活的TAB页: ${menu.text} > ${tabInfo.text}`); console.log(`⏭️ 跳过当前激活的TAB页: ${menu.text} > ${tabInfo.text}`);
hasSkippedActiveTab = true;
continue;
} }
await this.handleSingleTab(tabInfo, menu);
} }
} catch (error) { } catch (error) {
console.error(`处理TAB页失败 [${menu.text}]:`, error.message); console.error(`处理TAB页失败 [${menu.text}]:`, error.message);
@ -425,19 +436,22 @@ class LongiMainPage extends BasePage {
} }
/** /**
* 获取TAB页信息 * 处理单个TAB页
* @param {Array<Object>} tabs TAB页元素数组 * @param {Object} tabInfo TAB页信息对象
* @returns {Promise<Array>} TAB页信息数组 * @param {Object} parentMenu 父级菜单对象
* @private
*/ */
async findTabInfos(tabs) { async handleSingleTab(tabInfo, parentMenu) {
return Promise.all( try {
tabs.map(async element => ({ const menuPath = parentMenu.path || parentMenu.text;
text: await this.getTextByElement(element), const tabPath = `${menuPath} > ${tabInfo.text}`;
isActive: await element.evaluate(el => el.classList.contains('is-active')),
element: element console.log(`等待页面 ${tabPath} 数据加载...`);
})) await tabInfo.element.click();
); await this.waitForIBPPageLoadWithRetry(tabPath);
console.log(`✅ 页面 ${tabPath} 加载完成`);
} catch (error) {
console.error(`处理TAB页失败 [${tabPath}]:`, error.message);
}
} }
/** /**