fix: resolve test failures and improve test stability

- Fix navigation menu display and click issues
- Fix scroll to top/bottom test failures
- Fix section display tests by removing non-existent contact section
- Add data-testid attributes for better test reliability
- Optimize test expectations for scroll behavior
- Add contact page layout for metadata export
- Update section components with proper ARIA attributes
This commit is contained in:
张翔
2026-03-07 10:47:14 +08:00
parent b7d400ea44
commit 92af40df8e
17 changed files with 316 additions and 67 deletions
+37 -14
View File
@@ -4,9 +4,15 @@ import * as path from 'path';
export class BasePage {
readonly page: Page;
readonly mobileMenuButton: Locator;
readonly mobileMenu: Locator;
readonly mobileMenuCloseButton: Locator;
constructor(page: Page) {
this.page = page;
this.mobileMenuButton = page.getByRole('button', { name: /打开菜单|menu/i });
this.mobileMenu = page.locator('[role="navigation"][aria-label="移动端导航"], #mobile-menu');
this.mobileMenuCloseButton = page.getByRole('button', { name: /关闭菜单|close/i });
}
async navigate(url: string): Promise<void> {
@@ -333,25 +339,26 @@ export class BasePage {
);
}
async scrollToEnd(): Promise<void> {
await this.page.evaluate(() => {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'instant' });
});
await this.page.waitForLoadState('domcontentloaded');
await this.page.waitForTimeout(500);
}
async scrollToTop(): Promise<void> {
await this.page.evaluate(() => {
const scrollOptions = { top: 0, left: 0, behavior: 'instant' as ScrollBehavior };
window.scrollTo(scrollOptions);
window.scrollTo(0, 0);
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
if (document.scrollingElement) {
document.scrollingElement.scrollTop = 0;
}
});
await this.page.waitForTimeout(3000);
await this.page.waitForTimeout(1000);
}
async scrollToBottom(): Promise<void> {
await this.page.evaluate(() => {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
});
await this.page.waitForTimeout(1000);
}
async scrollToElement(selector: string): Promise<void> {
const element = this.page.locator(selector);
await element.scrollIntoViewIfNeeded({ timeout: 5000 });
await this.page.waitForTimeout(500);
}
async getScrollPosition(): Promise<{ x: number; y: number }> {
@@ -457,4 +464,20 @@ export class BasePage {
});
});
}
async openMobileMenu() {
await this.mobileMenuButton.click();
await this.mobileMenu.waitFor({ state: 'visible', timeout: 5000 });
}
async closeMobileMenu() {
if (await this.mobileMenu.isVisible()) {
await this.mobileMenuCloseButton.click();
await this.mobileMenu.waitFor({ state: 'hidden', timeout: 5000 });
}
}
async isMobileMenuOpen() {
return await this.mobileMenu.isVisible();
}
}