import { spawn } from 'child_process'; const edgePath = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'; console.log('Launching Edge headless with CDP...'); const edge = spawn(edgePath, [ '--headless', '--remote-debugging-port=9222', '--disable-gpu', 'http://192.168.2.79:8080/' ]); edge.on('error', (err) => console.error('Edge spawn error:', err)); await new Promise(r => setTimeout(r, 2500)); try { const listRes = await fetch('http://127.0.0.1:9222/json'); const targets = await listRes.json(); console.log('CDP targets found:', targets.length); const page = targets.find(t => t.type === 'page' && t.url.includes('192.168.2.79:8080')); if (!page) { console.error('Target page not found in CDP targets:', targets); edge.kill(); process.exit(1); } const ws = new WebSocket(page.webSocketDebuggerUrl); ws.onopen = async () => { console.log('Connected to page CDP WebSocket'); await new Promise(r => setTimeout(r, 2000)); ws.send(JSON.stringify({ id: 10, method: 'Runtime.evaluate', params: { expression: `(() => { const title = document.title; const ver = document.getElementById('sys-version')?.innerText; const mode = document.getElementById('sys-mode')?.innerText; const stationCards = Array.from(document.querySelectorAll('.station-card')).map(c => ({ id: c.getAttribute('data-id'), name: c.querySelector('.station-name')?.innerText, status: c.querySelector('.status-tag')?.innerText })); // Click Start Test button to open modal const startBtn = document.getElementById('btn-open-start'); startBtn?.click(); const modalOpen = !document.getElementById('modal-start-run')?.classList.contains('hidden'); // Close modal document.getElementById('btn-close-modal-start')?.click(); const modalClosed = document.getElementById('modal-start-run')?.classList.contains('hidden'); // Check 24 dimm slots in CPU0 and CPU1 const cpu0Slots = document.querySelectorAll('#cpu0-grid .dimm-slot').length; const cpu1Slots = document.querySelectorAll('#cpu1-grid .dimm-slot').length; return { title, version: ver, mode: mode, stations: stationCards, modal_open_test: modalOpen, modal_closed_test: modalClosed, cpu0_slots: cpu0Slots, cpu1_slots: cpu1Slots }; })()`, returnByValue: true } })); }; ws.onmessage = (evt) => { const msg = JSON.parse(evt.data); if (msg.id === 10) { console.log('BROWSER_TEST_SUCCESS:'); console.log(JSON.stringify(msg.result?.result?.value, null, 2)); ws.close(); edge.kill(); process.exit(0); } }; ws.onerror = (err) => { console.error('WebSocket error:', err); edge.kill(); process.exit(1); }; } catch (e) { console.error('Test execution error:', e); edge.kill(); process.exit(1); } setTimeout(() => { console.error('Browser test timeout'); edge.kill(); process.exit(1); }, 12000);