Root cause: milestone test was the first to run after global-setup completed the wizard configuration. The backend needed time to detect the config file and run database migrations, but tests started immediately. This caused /auth/token requests to fail with net::ERR_FAILED. Changes: - global-setup.ts: after wizard setup, poll backend /docs until it returns 200 - milestone.spec.ts: add retry loop (max 3 attempts) for login as extra safety and assert token presence before proceeding
110 lines
4.4 KiB
TypeScript
110 lines
4.4 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');
|
|
}
|
|
|
|
// Wait for backend to be ready (it starts after config file is written)
|
|
const backendURL = process.env.BACKEND_URL || 'http://backend:8000';
|
|
console.log('⏳ Waiting for backend to be ready...');
|
|
const maxRetries = 30;
|
|
for (let i = 0; i < maxRetries; i++) {
|
|
try {
|
|
const resp = await page.request.get(`${backendURL}/docs`, { timeout: 3000 });
|
|
if (resp.ok()) {
|
|
console.log('✅ Backend is ready!');
|
|
break;
|
|
}
|
|
} catch {
|
|
// backend not ready yet
|
|
}
|
|
if (i === maxRetries - 1) {
|
|
console.warn('⚠️ Backend did not respond after retries, proceeding anyway...');
|
|
} else {
|
|
console.log(` Waiting for backend... (${i + 1}/${maxRetries})`);
|
|
await new Promise(r => setTimeout(r, 2000));
|
|
}
|
|
}
|
|
|
|
await browser.close();
|
|
return;
|
|
} catch (error) {
|
|
console.error('❌ Wizard setup failed:', error);
|
|
await browser.close();
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export default setupWizard;
|