import { chromium } from 'playwright'; import fs from 'fs'; (async () => { console.log('=== Servers Download Test ===\n'); const browser = await chromium.launch({ headless: false, slowMo: 500 }); const context = await browser.newContext(); const page = await context.newPage(); const errors = []; const networkLogs = []; // Capture console page.on('console', msg => { const text = msg.text(); console.log(`[CONSOLE ${msg.type()}] ${text}`); if (msg.type() === 'error' || text.includes('ERROR') || text.includes('šŸ”“')) { errors.push({ type: 'console', text: text }); } }); // Capture network page.on('request', request => { if (request.url().includes('api/v1')) { networkLogs.push({ type: 'request', method: request.method(), url: request.url() }); console.log(`šŸ“¤ ${request.method()} ${request.url()}`); } }); page.on('response', async response => { if (response.url().includes('api/v1')) { const status = response.status(); const url = response.url(); let body = null; try { body = await response.text(); } catch (e) { body = '[Could not read body]'; } networkLogs.push({ type: 'response', status: status, url: url, body: body }); const icon = status >= 400 ? 'āŒ' : 'āœ…'; console.log(`${icon} ${status} ${url}`); console.log(` Body: ${body.substring(0, 200)}...`); if (status >= 400) { errors.push({ status, url, body }); } } }); try { console.log('1ļøāƒ£ Navigating and logging in...'); await page.goto('http://100.81.138.77:8081/', { waitUntil: 'networkidle', timeout: 60000 }); await page.waitForTimeout(3000); // Login await page.keyboard.press('Tab'); await page.keyboard.type('admin', { delay: 100 }); await page.keyboard.press('Tab'); await page.keyboard.type('admin123', { delay: 100 }); await page.keyboard.press('Enter'); await page.waitForTimeout(5000); console.log('\n2ļøāƒ£ Navigating to Servers Management...'); await page.goto('http://100.81.138.77:8081/#/servers', { waitUntil: 'networkidle', timeout: 60000 }); await page.waitForTimeout(3000); await page.screenshot({ path: 'servers-page.png' }); console.log('\n3ļøāƒ£ Clicking download servers button...'); // Tab to download button (skip search button, sync button, then download) await page.keyboard.press('Tab'); await page.keyboard.press('Tab'); await page.keyboard.press('Tab'); await page.keyboard.press('Enter'); console.log(' Waiting for response...'); await page.waitForTimeout(8000); await page.screenshot({ path: 'servers-after-download.png' }); } catch (error) { console.error('\nāŒ Test error:', error.message); await page.screenshot({ path: 'servers-error.png' }); errors.push({ error: error.message }); } // Summary console.log('\n' + '='.repeat(60)); console.log('SUMMARY'); console.log('='.repeat(60)); console.log(`\nErrors: ${errors.length}`); if (errors.length > 0) { console.log('\nāŒ ERRORS DETECTED:'); errors.forEach((err, i) => { console.log(`\nError ${i + 1}:`); if (err.status) { console.log(` HTTP ${err.status}: ${err.url}`); console.log(` Response: ${err.body}`); } else if (err.text) { console.log(` Console: ${err.text}`); } else { console.log(` ${err.error}`); } }); } // Save logs fs.writeFileSync('servers-test-results.json', JSON.stringify({ errors, networkLogs }, null, 2)); console.log('\nšŸ“Š Logs saved to: servers-test-results.json'); await page.waitForTimeout(3000); await browser.close(); console.log('\n=== Test Complete ==='); process.exit(errors.length > 0 ? 1 : 0); })();