69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { Page, expect } from '@playwright/test';
|
|
|
|
export class FrontendHomePage {
|
|
readonly page: Page;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.goto('/');
|
|
await this.page.waitForLoadState('domcontentloaded');
|
|
}
|
|
|
|
async expectHeroVisible() {
|
|
await expect(this.page.locator('h1')).toBeVisible();
|
|
await expect(this.page.locator('text=专业')).toBeVisible();
|
|
}
|
|
|
|
async expectServicesVisible() {
|
|
await expect(this.page.locator('#services')).toBeVisible();
|
|
}
|
|
|
|
async scrollToSection(sectionId: string) {
|
|
await this.page.locator(`#${sectionId}`).scrollIntoViewIfNeeded();
|
|
await expect(this.page.locator(`#${sectionId}`)).toBeVisible();
|
|
}
|
|
|
|
async expectServiceCardsVisible() {
|
|
const serviceCards = this.page.locator('[data-testid="service-card"], article');
|
|
const count = await serviceCards.count();
|
|
expect(count).toBeGreaterThan(0);
|
|
}
|
|
|
|
async clickFirstCase() {
|
|
const firstCase = this.page.locator('#cases a, [data-testid="case-card"] a').first();
|
|
if (await firstCase.count() > 0) {
|
|
await firstCase.click();
|
|
}
|
|
}
|
|
|
|
async clickFirstProduct() {
|
|
const firstProduct = this.page.locator('#products a, [data-testid="product-card"] a').first();
|
|
if (await firstProduct.count() > 0) {
|
|
await firstProduct.click();
|
|
}
|
|
}
|
|
|
|
async expectMobileMenuButtonVisible() {
|
|
const menuButton = this.page.locator('button[aria-label="菜单"], button:has-text("菜单")');
|
|
await expect(menuButton).toBeVisible();
|
|
}
|
|
|
|
async clickMobileMenuButton() {
|
|
const menuButton = this.page.locator('button[aria-label="菜单"], button:has-text("菜单")');
|
|
await menuButton.click();
|
|
}
|
|
|
|
async expectMobileMenuOpen() {
|
|
const mobileMenu = this.page.locator('[role="dialog"], nav[data-state="open"]');
|
|
await expect(mobileMenu).toBeVisible();
|
|
}
|
|
|
|
async clickMobileMenuItem(itemText: string) {
|
|
const menuItem = this.page.locator(`nav a:has-text("${itemText}"), [role="dialog"] a:has-text("${itemText}")`);
|
|
await menuItem.click();
|
|
}
|
|
}
|