feat: add page objects for all pages

This commit is contained in:
张翔
2026-03-06 12:07:18 +08:00
parent b8d22aac9f
commit 50ecd7a241
8 changed files with 148 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class AboutPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('about');
super(page, pageConfig.url, config);
}
async getPageTitle(): Promise<string> {
return await this.getText('h1');
}
async getContent(): Promise<string> {
return await this.getText('.about-content');
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class CasesPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('cases');
super(page, pageConfig.url, config);
}
async getCaseCount(): Promise<number> {
return await this.page.locator('.case-card').count();
}
}
@@ -0,0 +1,29 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class ContactPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('contact');
super(page, pageConfig.url, config);
}
async fillContactForm(data: { name: string; email: string; phone: string; message: string }): Promise<void> {
await this.fill('#name', data.name);
await this.fill('#email', data.email);
await this.fill('#phone', data.phone);
await this.fill('#message', data.message);
}
async submitForm(): Promise<void> {
await this.click('button[type="submit"]');
}
async getFormErrorMessage(): Promise<string> {
return await this.getText('.error-message');
}
async getFormSuccessMessage(): Promise<string> {
return await this.getText('.success-message');
}
}
+33
View File
@@ -0,0 +1,33 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class HomePage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('home');
super(page, pageConfig.url, config);
this.pageConfig = pageConfig;
}
private pageConfig;
async getHeroTitle(): Promise<string> {
return await this.getText('h1');
}
async getFeaturesSection(): Promise<boolean> {
return await this.isVisible('.features-section');
}
async navigateToAbout(): Promise<void> {
await this.click('a[href="/about"]');
}
async navigateToContact(): Promise<void> {
await this.click('a[href="/contact"]');
}
async navigateToProducts(): Promise<void> {
await this.click('a[href="/products"]');
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class NewsPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('news');
super(page, pageConfig.url, config);
}
async getNewsCount(): Promise<number> {
return await this.page.locator('.news-item').count();
}
}
@@ -0,0 +1,18 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class ProductsPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('products');
super(page, pageConfig.url, config);
}
async getProductCount(): Promise<number> {
return await this.page.locator('.product-card').count();
}
async getProductTitle(index: number): Promise<string> {
return await this.getText(`.product-card:nth-child(${index + 1}) h3`);
}
}
@@ -0,0 +1,14 @@
import { Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { getPageConfig } from '../config/test-pages';
export class ServicesPage extends BasePage {
constructor(page: Page, config?) {
const pageConfig = getPageConfig('services');
super(page, pageConfig.url, config);
}
async getServiceCount(): Promise<number> {
return await this.page.locator('.service-item').count();
}
}
+8
View File
@@ -0,0 +1,8 @@
export { BasePage } from './BasePage';
export { HomePage } from './HomePage';
export { AboutPage } from './AboutPage';
export { ContactPage } from './ContactPage';
export { ProductsPage } from './ProductsPage';
export { ServicesPage } from './ServicesPage';
export { CasesPage } from './CasesPage';
export { NewsPage } from './NewsPage';