35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
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; subject?: string }): Promise<void> {
|
|
await this.fill('[data-testid="name-input"]', data.name);
|
|
await this.fill('[data-testid="phone-input"]', data.phone);
|
|
await this.fill('[data-testid="email-input"]', data.email);
|
|
if (data.subject) {
|
|
await this.fill('[data-testid="subject-input"]', data.subject);
|
|
}
|
|
await this.fill('[data-testid="message-input"]', data.message);
|
|
}
|
|
|
|
async submitForm(): Promise<void> {
|
|
await this.click('[data-testid="submit-button"]');
|
|
}
|
|
|
|
async getFormErrorMessage(): Promise<string> {
|
|
const errorElement = await this.page.locator('[data-testid="name-input"]').locator('..').locator('p.text-red-500').first();
|
|
return await errorElement.textContent() || '';
|
|
}
|
|
|
|
async getFormSuccessMessage(): Promise<string> {
|
|
const successElement = await this.page.locator('text=消息已发送').first();
|
|
return await successElement.textContent() || '';
|
|
}
|
|
}
|