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