diff --git a/test-framework/shared/pages/ContactPage.ts b/test-framework/shared/pages/ContactPage.ts index 2e2eeaf..14923a1 100644 --- a/test-framework/shared/pages/ContactPage.ts +++ b/test-framework/shared/pages/ContactPage.ts @@ -23,16 +23,44 @@ export class ContactPage extends BasePage { } async getFormErrorMessage(): Promise { - const errorElement = await this.page.locator('p.mt-1.text-sm.text-\\[\\#C41E3A\\]').first(); + const errorElement = await this.page.locator('[data-testid="error-message"]').first(); return await errorElement.textContent() || ''; } async getFormSuccessMessage(): Promise { await this.page.waitForTimeout(1000); - const successElement = await this.page.locator('text=消息已发送').first(); + const successElement = await this.page.locator('[data-testid="success-message"]'); if (await successElement.count() > 0) { return await successElement.textContent() || ''; } return ''; } + + async getToastMessage(): Promise<{ message: string; type: 'success' | 'error' }> { + const toastElement = await this.page.locator('[data-testid="toast-notification"]'); + if (await toastElement.count() > 0) { + const message = await toastElement.textContent() || ''; + const type = await toastElement.getAttribute('data-type') as 'success' | 'error'; + return { message, type }; + } + return { message: '', type: 'success' }; + } + + async waitForToast(timeout: number = 5000): Promise { + try { + await this.page.waitForSelector('[data-testid="toast-notification"]', { timeout }); + return true; + } catch { + return false; + } + } + + async waitForToastHidden(timeout: number = 5000): Promise { + try { + await this.page.waitForSelector('[data-testid="toast-notification"]', { state: 'hidden', timeout }); + return true; + } catch { + return false; + } + } }