fix(mobile-menu): 修复移动菜单测试 - 适配锚点导航和Firefox点击问题
问题: - 测试期望点击菜单项后URL变化,但实际是页面内锚点导航 - Firefox浏览器点击操作超时 修复: 1. 测试:修改验证逻辑,检查页面区域可见性而非URL变化 2. 页面对象:增加button选择器和JavaScript点击fallback 3. 页面对象:增加滚动到视图和更长的超时时间 测试结果: - Chromium: ✓ 通过 - Firefox: ✓ 通过
This commit is contained in:
@@ -176,7 +176,8 @@ export class FrontendHomePage {
|
||||
`#mobile-menu a:has-text("${itemText}")`,
|
||||
`[data-testid="mobile-navigation"] a:has-text("${itemText}")`,
|
||||
`nav a:has-text("${itemText}")`,
|
||||
`[role="navigation"] a:has-text("${itemText}")`
|
||||
`[role="navigation"] a:has-text("${itemText}")`,
|
||||
`button:has-text("${itemText}")`
|
||||
];
|
||||
|
||||
let menuItem = null;
|
||||
@@ -196,18 +197,36 @@ export class FrontendHomePage {
|
||||
}
|
||||
|
||||
if (!menuItem) {
|
||||
const allLinks = await this.page.locator('nav a, [role="navigation"] a').allTextContents();
|
||||
const allLinks = await this.page.locator('nav a, [role="navigation"] a, nav button').allTextContents();
|
||||
console.log('所有导航链接文本:', allLinks);
|
||||
throw new Error(`未找到可见的菜单项 "${itemText}"`);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.page.waitForTimeout(200);
|
||||
await menuItem.click({ timeout: 5000, force: true });
|
||||
|
||||
try {
|
||||
await menuItem.scrollIntoViewIfNeeded({ timeout: 3000 });
|
||||
} catch {
|
||||
console.log('滚动到菜单项失败,继续尝试点击');
|
||||
}
|
||||
|
||||
await this.page.waitForTimeout(300);
|
||||
|
||||
await menuItem.click({ timeout: 10000, force: true });
|
||||
console.log(`成功点击菜单项 "${itemText}"`);
|
||||
} catch (error) {
|
||||
console.log(`点击菜单项 "${itemText}" 失败:`, error);
|
||||
throw error;
|
||||
console.log(`点击菜单项 "${itemText}" 失败,尝试使用JavaScript点击:`, error);
|
||||
|
||||
try {
|
||||
await menuItem.evaluate((el) => {
|
||||
(el as HTMLElement).click();
|
||||
});
|
||||
console.log(`使用JavaScript成功点击菜单项 "${itemText}"`);
|
||||
} catch (jsError) {
|
||||
console.log(`JavaScript点击也失败:`, jsError);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user