import { Page } from '@playwright/test' /** * Helper to login and navigate to chat page * * Uses environment variables for test credentials: * - TEST_USER_EMAIL: Email for test account * - TEST_USER_PASSWORD: Password for test account * * Run tests with credentials: * TEST_USER_EMAIL=your@email.com TEST_USER_PASSWORD=yourpass pnpm test:e2e */ export async function loginAndNavigate(page: Page): Promise { await page.goto('/') // Get credentials from environment variables const email = process.env.TEST_USER_EMAIL const password = process.env.TEST_USER_PASSWORD if (!email || !password) { throw new Error( 'TEST_USER_EMAIL and TEST_USER_PASSWORD environment variables are required.\n' + 'Run: TEST_USER_EMAIL=your@email.com TEST_USER_PASSWORD=yourpass pnpm test:e2e' ) } // Check if already logged in (chat-input visible) const chatInput = page.getByTestId('chat-input') try { await chatInput.waitFor({ state: 'visible', timeout: 2000 }) return // Already logged in } catch { // Not logged in, continue with login flow } // Perform login const emailInput = page.getByRole('textbox', { name: /e-mail/i }) const passwordInput = page.getByRole('textbox', { name: /wachtwoord/i }) const loginButton = page.getByRole('button', { name: /inloggen/i }) await emailInput.fill(email) await passwordInput.fill(password) await loginButton.click() // Wait for chat page to load await page.waitForSelector('[data-testid="chat-input"]', { timeout: 30000 }) } /** * Wait for chat interface to be ready */ export async function waitForChatReady(page: Page): Promise { await page.waitForSelector('[data-testid="chat-input"]', { timeout: 10000 }) await page.waitForSelector('[data-testid="send-button"]', { timeout: 10000 }) }