第一次
This commit is contained in:
parent
edb505c1f3
commit
84f9d72471
@ -491,6 +491,9 @@ class LongiMainPage extends BasePage {
|
|||||||
await this.expandSideMenu();
|
await this.expandSideMenu();
|
||||||
if (menu.hasThirdMenu) {
|
if (menu.hasThirdMenu) {
|
||||||
await this.handleThreeLevelMenu(menu);
|
await this.handleThreeLevelMenu(menu);
|
||||||
|
} else {
|
||||||
|
// 处理二级菜单点击
|
||||||
|
await this.handleMenuClick(menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,19 +627,14 @@ class LongiMainPage extends BasePage {
|
|||||||
*/
|
*/
|
||||||
async clickAndWaitThirdMenuItem(menu, currentMenuText) {
|
async clickAndWaitThirdMenuItem(menu, currentMenuText) {
|
||||||
try {
|
try {
|
||||||
const currentThirdMenuItem = await this.page.locator(this.selectors.thirdLevelMenu)
|
const currentThirdMenuItem = {
|
||||||
.filter({hasText: currentMenuText})
|
text: currentMenuText,
|
||||||
.first();
|
element: await this.page.locator(this.selectors.thirdLevelMenu)
|
||||||
|
.filter({hasText: currentMenuText})
|
||||||
|
.first()
|
||||||
|
};
|
||||||
|
|
||||||
await currentThirdMenuItem.click();
|
await this.handleMenuClick(currentThirdMenuItem, menu.text);
|
||||||
const loadResult = await this.waitForPageLoadWithRetry(menu, currentMenuText);
|
|
||||||
|
|
||||||
if (!loadResult.success) {
|
|
||||||
console.warn(loadResult.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在页面加载完成后关闭标签页
|
|
||||||
await this.closeActiveTab(`${menu.text} > ${currentMenuText}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`点击三级菜单项失败 [${currentMenuText}]:`, error.message);
|
console.error(`点击三级菜单项失败 [${currentMenuText}]:`, error.message);
|
||||||
}
|
}
|
||||||
@ -685,6 +683,42 @@ class LongiMainPage extends BasePage {
|
|||||||
console.error(`处理三级菜单时出错 [${menu.text}]:`, error.message);
|
console.error(`处理三级菜单时出错 [${menu.text}]:`, error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用的菜单点击和页面加载处理方法
|
||||||
|
* @param {Object} menuInfo 菜单信息对象,包含text属性
|
||||||
|
* @param {string} parentText 父级菜单文本(可选)
|
||||||
|
* @returns {Promise<boolean>} 处理是否成功
|
||||||
|
*/
|
||||||
|
async handleMenuClick(menuInfo, parentText = '') {
|
||||||
|
try {
|
||||||
|
const menuPath = parentText ? `${parentText} > ${menuInfo.text}` : menuInfo.text;
|
||||||
|
console.log(`🔸 点击菜单: ${menuPath}`);
|
||||||
|
|
||||||
|
// 点击菜单项
|
||||||
|
if (menuInfo.element) {
|
||||||
|
await menuInfo.element.click();
|
||||||
|
} else {
|
||||||
|
// 如果没有element属性,尝试通过文本定位
|
||||||
|
const menuLocator = this.page.locator(`text=${menuInfo.text}`).first();
|
||||||
|
await menuLocator.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待页面加载
|
||||||
|
const loadResult = await this.waitForPageLoadWithRetry({ text: menuPath });
|
||||||
|
if (!loadResult.success) {
|
||||||
|
console.warn(loadResult.error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭标签页
|
||||||
|
await this.closeActiveTab(menuPath);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`处理菜单点击失败 [${menuInfo.text}]:`, error.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = LongiMainPage;
|
module.exports = LongiMainPage;
|
||||||
Loading…
Reference in New Issue
Block a user