import { Page, expect } from '@playwright/test'; export class ChatHelper { constructor(private page: Page) {} async sendMessage(message: string) { const input = this.page.locator('textarea[placeholder*="Type"], input[placeholder*="Type"]'); await input.fill(message); await input.press('Enter'); } async waitForAIResponse() { // Wait for typing indicator to appear then disappear const typingIndicator = this.page.locator('[data-testid="typing-indicator"]').first(); try { await typingIndicator.waitFor({ state: 'visible', timeout: 2000 }); await typingIndicator.waitFor({ state: 'hidden', timeout: 30000 }); } catch { // Typing indicator might not appear for fast responses await this.page.waitForTimeout(1000); } } async getLastMessage() { const messages = this.page.locator('[data-testid="chat-message"]'); const count = await messages.count(); return count > 0 ? messages.nth(count - 1) : null; } async getMessageCount() { const messages = this.page.locator('[data-testid="chat-message"]'); return await messages.count(); } }