import { chromium } from '@playwright/test'; const WIZARD_URL = process.env.WIZARD_URL || 'http://wizard:8080/wizard'; const WIZARD_API_URL = process.env.WIZARD_API_URL || 'http://wizard:8080'; async function setupWizard() { console.log('🔧 Running global setup: Configure wizard...'); const browser = await chromium.launch(); const page = await browser.newPage(); try { // Navigate to frontend - should redirect to wizard since not configured const frontendURL = process.env.FRONTEND_URL || 'http://frontend:3000'; console.log(`📱 Navigating to ${frontendURL}...`); await page.goto(frontendURL); await page.waitForLoadState('networkidle'); // Step 0: Welcome await page.waitForSelector('h1:has-text("HarborForge")', { timeout: 10000 }); const connectButton = page.locator('button:has-text("Connect to Wizard")'); if (await connectButton.isVisible().catch(() => false)) { console.log('🔗 Clicking Connect to Wizard...'); await connectButton.click(); // Wait for step 1: Database console.log('📝 Filling Database configuration...'); await page.waitForSelector('h2:has-text("Database configuration")', { timeout: 10000 }); await page.locator('label:has-text("Host") input').fill('mysql'); await page.locator('label:has-text("Port") input').fill('3306'); await page.locator('label:has-text("Username") input').fill('harborforge'); await page.locator('label:has-text("Password") input').fill('harborforge_pass'); await page.locator('label:has-text("Database") input').fill('harborforge'); await page.click('button:has-text("Next")'); // Wait for step 2: Admin console.log('📝 Filling Admin account...'); await page.waitForSelector('h2:has-text("Admin account")', { timeout: 10000 }); await page.locator('label:has-text("Password") input').fill('admin123'); await page.locator('label:has-text("Email") input').fill('admin@test.com'); await page.locator('label:has-text("Full name") input').fill('Test Admin'); await page.click('button:has-text("Next")'); // Wait for step 3: Backend URL console.log('📝 Filling Backend URL...'); await page.waitForSelector('h2:has-text("Backend URL")', { timeout: 10000 }); const backendURL = process.env.BACKEND_URL || 'http://backend:8000'; await page.locator('label:has-text("Backend Base URL") input').fill(backendURL); await page.click('button:has-text("Finish setup")'); // Wait for step 4: Complete console.log('✅ Waiting for setup complete...'); await page.waitForSelector('h2:has-text("Setup complete!")', { timeout: 10000 }); console.log('✅ Wizard configured successfully!'); } else { console.log('⚠️ Wizard already configured or on main page'); } await browser.close(); return; } catch (error) { console.error('❌ Wizard setup failed:', error); await browser.close(); throw error; } } export default setupWizard;