Files
HarborForge.Frontend.Test/global-setup.ts
2026-03-14 08:47:12 +00:00

88 lines
3.6 KiB
TypeScript

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
console.log('⏳ Waiting for wizard page...');
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 the step to change after clicking
await page.waitForTimeout(3000);
// Check what's on the page now
const pageContent = await page.content();
console.log('Page after click:', pageContent.substring(0, 2000));
// Wait for step 1: Database
console.log('📝 Waiting for Database configuration...');
try {
await page.waitForSelector('h2:has-text("Database configuration")', { timeout: 5000 });
} catch (e) {
console.log('Could not find Database config, trying alternate selector...');
// Try waiting for any h2
await page.waitForSelector('h2', { timeout: 5000 });
console.log('Found h2:', await page.locator('h2').first().textContent());
}
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;