import { test as setup, expect } from '@playwright/test'; import path from 'path'; const authFile = path.join(__dirname, '.auth', 'user.json'); /** * Global setup for authentication * This runs once before all tests and saves the authenticated state * Other tests can reuse this state to avoid logging in repeatedly */ setup('authenticate', async ({ page }) => { // Navigate to login page await page.goto('/login'); // TODO: Update these credentials with your test user // For now, we'll use environment variables or default test credentials const testEmail = process.env.TEST_USER_EMAIL || 'test@bakery.com'; const testPassword = process.env.TEST_USER_PASSWORD || 'test-password-123'; // Fill in login form await page.getByLabel(/email/i).fill(testEmail); await page.getByLabel(/password/i).fill(testPassword); // Click login button await page.getByRole('button', { name: /log in|sign in|login/i }).click(); // Wait for redirect to dashboard or app await page.waitForURL(/\/(app|dashboard)/); // Verify we're logged in by checking for user-specific elements // Adjust this selector based on your actual app structure await expect(page.locator('body')).toContainText(/dashboard|panel de control/i, { timeout: 10000, }); // Save authenticated state await page.context().storageState({ path: authFile }); console.log('✅ Authentication setup complete'); });