第一次
This commit is contained in:
parent
2589f3479b
commit
67149da27a
@ -32,5 +32,5 @@ test('隆基登录', async ({page}) => {
|
||||
// 11. 使用菜单数据进行后续操作
|
||||
console.log(`共有 ${menuItems.length} 个菜单项可用于测试`);
|
||||
|
||||
await mainPage.handleAllMenus(menuItems);
|
||||
await mainPage.handleAllMenuClicks(menuItems);
|
||||
});
|
||||
|
||||
@ -481,9 +481,9 @@ class LongiMainPage extends BasePage {
|
||||
}
|
||||
}
|
||||
|
||||
async handleAllMenus(menuItems) {
|
||||
async handleAllMenuClicks(menuItems) {
|
||||
for (let i = 0; i < menuItems.length; i++) {
|
||||
await this.handleSingleMenu(menuItems[i]);
|
||||
await this.handleSingleMenuClick(menuItems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -547,7 +547,8 @@ class LongiMainPage extends BasePage {
|
||||
}
|
||||
}
|
||||
|
||||
async handleSingleMenu(menu) {
|
||||
async handleSingleMenuClick(menu) {
|
||||
try {
|
||||
await this.expandSideMenu();
|
||||
// 在处理菜单前重新获取最新的element
|
||||
menu = await this.restoreMenuElement(menu);
|
||||
@ -563,6 +564,27 @@ class LongiMainPage extends BasePage {
|
||||
// 处理二级菜单点击
|
||||
await this.handleMenuClick(menu);
|
||||
}
|
||||
|
||||
// 执行内存回收
|
||||
await this.page.evaluate(() => {
|
||||
// 清理DOM中的临时元素
|
||||
const cleanup = () => {
|
||||
const elements = document.querySelectorAll('.el-loading-mask, .el-message, .el-message-box');
|
||||
elements.forEach(el => el.remove());
|
||||
|
||||
// 如果浏览器支持手动垃圾回收,则执行
|
||||
if (window.gc) {
|
||||
window.gc();
|
||||
}
|
||||
};
|
||||
cleanup();
|
||||
});
|
||||
console.log(`🧹 执行内存回收 - ${menu.text}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error(`处理菜单失败 [${menu.text}]:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -573,7 +595,6 @@ class LongiMainPage extends BasePage {
|
||||
*/
|
||||
async waitForPageLoadWithRetry(menu, subMenuText = '') {
|
||||
const pageName = subMenuText ? `${menu.text} > ${subMenuText}` : menu.text;
|
||||
const pageStartTime = Date.now();
|
||||
console.log(`等待页面 ${pageName} 数据加载...`);
|
||||
|
||||
const config = {
|
||||
@ -714,7 +735,7 @@ class LongiMainPage extends BasePage {
|
||||
|
||||
// 这里可以根据需要处理三级菜单项
|
||||
for (const thirdMenu of thirdMenus) {
|
||||
await this.handleMenuClick(thirdMenu, menu.text);
|
||||
await this.handleMenuClick(thirdMenu, menu);
|
||||
|
||||
// 如果不是最后一个菜单项,需要重新点击父菜单展开三级菜单
|
||||
if (thirdMenu !== thirdMenus[thirdMenus.length - 1]) {
|
||||
@ -732,28 +753,23 @@ class LongiMainPage extends BasePage {
|
||||
/**
|
||||
* 通用的菜单点击和页面加载处理方法
|
||||
* @param {Object} menuInfo 菜单信息对象,包含text属性
|
||||
* @param {string} parentText 父级菜单文本(可选)
|
||||
* @param {Object} parentMenu 父级菜单(可选)
|
||||
* @returns {Promise<boolean>} 处理是否成功
|
||||
*/
|
||||
async handleMenuClick(menuInfo, parentText = '') {
|
||||
async handleMenuClick(menuInfo, parentMenu) {
|
||||
try {
|
||||
const menuPath = parentText ? `${parentText} > ${menuInfo.text}` : menuInfo.text;
|
||||
const menuPath = parentMenu.text ? `${parentMenu.text} > ${menuInfo.text}` : menuInfo.text;
|
||||
console.log(`🔸 点击菜单: ${menuPath}`);
|
||||
|
||||
await menuInfo.element.click();
|
||||
|
||||
// 等待页面加载
|
||||
const loadResult = await this.waitForPageLoadWithRetry(menuInfo);
|
||||
if (!loadResult) {
|
||||
console.warn('页面加载失败');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (loadResult) {
|
||||
// 处理所有TAB页
|
||||
await this.handleAllTabs(menuInfo);
|
||||
|
||||
// 关闭标签页
|
||||
await this.closeActiveTab(menuPath);
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`处理菜单点击失败 [${menuInfo.text}]:`, error.message);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user