import { Page, expect } from '@playwright/test'; import { ContactFormData } from '../fixtures/test-data-factory'; export class FrontendContactPage { readonly page: Page; constructor(page: Page) { this.page = page; } async goto() { await this.page.goto('/contact'); await this.page.waitForLoadState('domcontentloaded'); } async expectContactInfoVisible() { await expect(this.page.locator('text=电话')).toBeVisible(); await expect(this.page.locator('text=邮箱')).toBeVisible(); } async expectContactFormVisible() { await expect(this.page.locator('form')).toBeVisible(); } async fillForm(data: ContactFormData) { await this.page.fill('input[name="name"]', data.name); await this.page.fill('input[name="email"]', data.email); if (data.phone) { await this.page.fill('input[name="phone"]', data.phone); } if (data.company) { await this.page.fill('input[name="company"]', data.company); } await this.page.fill('textarea[name="message"]', data.message); } async submitForm() { await this.page.click('button[type="submit"]'); } async expectSubmitSuccess() { await expect( this.page.locator('text=提交成功, text=发送成功, [role="status"]') ).toBeVisible({ timeout: 10000 }); } async expectConfirmationVisible() { await expect( this.page.locator('text=感谢, text=我们会尽快联系您') ).toBeVisible(); } }