fix(e2e): 修复移动端导航测试菜单项选择器问题
- 使用多种选择器策略查找菜单项 - 增强移动菜单打开状态检测 - 添加详细的调试日志 - 添加移动菜单调试测试 任务 3/4
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { test, expect, devices } from '@playwright/test';
|
||||
|
||||
test.use({ ...devices['Pixel 5'] });
|
||||
|
||||
test.describe('移动菜单调试测试', () => {
|
||||
test.setTimeout(60000);
|
||||
|
||||
test('调试移动菜单打开', async ({ page }) => {
|
||||
console.log('=== 步骤1: 打开首页 ===');
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
|
||||
console.log('=== 步骤2: 查找菜单按钮 ===');
|
||||
const menuButton = page.locator('button[aria-label*="菜单"], button[aria-label*="menu"], button[aria-label*="Menu"], button[data-testid="mobile-menu-button"]');
|
||||
const buttonCount = await menuButton.count();
|
||||
console.log(`找到 ${buttonCount} 个菜单按钮`);
|
||||
|
||||
if (buttonCount > 0) {
|
||||
console.log('=== 步骤3: 点击菜单按钮 ===');
|
||||
await menuButton.first().click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
console.log('=== 步骤4: 检查移动菜单是否打开 ===');
|
||||
const mobileMenu = page.locator('#mobile-menu, [data-testid="mobile-navigation"]');
|
||||
const menuCount = await mobileMenu.count();
|
||||
console.log(`找到 ${menuCount} 个移动菜单`);
|
||||
|
||||
if (menuCount > 0) {
|
||||
const isVisible = await mobileMenu.first().isVisible();
|
||||
console.log(`移动菜单是否可见: ${isVisible}`);
|
||||
|
||||
if (isVisible) {
|
||||
console.log('=== 步骤5: 查找所有菜单项 ===');
|
||||
const allLinks = await mobileMenu.first().locator('a').allTextContents();
|
||||
console.log('所有菜单项文本:', allLinks);
|
||||
|
||||
console.log('=== 步骤6: 查找"产品服务"菜单项 ===');
|
||||
const productLink = mobileMenu.first().locator('a:has-text("产品服务")');
|
||||
const productCount = await productLink.count();
|
||||
console.log(`找到 ${productCount} 个"产品服务"菜单项`);
|
||||
|
||||
if (productCount > 0) {
|
||||
const isProductVisible = await productLink.first().isVisible();
|
||||
console.log(`"产品服务"菜单项是否可见: ${isProductVisible}`);
|
||||
|
||||
if (isProductVisible) {
|
||||
console.log('=== 步骤7: 点击"产品服务"菜单项 ===');
|
||||
await productLink.first().click();
|
||||
await page.waitForTimeout(1000);
|
||||
console.log('点击成功,当前URL:', page.url());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user