优化分批执行点击菜单

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