library-run.mjs (1365B)
1 // Lance un programme de la bibliothèque par son titre (clic sur l'entrée .pg, comme un visiteur), 2 // attend l'auto-chargement (ExelBASIC + cassette, LOAD"1"/RUN) et capture l'écran. 3 // node test/library-run.mjs <bout de titre> [base-url] [capture.png] [secondes] 4 import { open, sleep } from './cdp.mjs'; 5 6 const want = (process.argv[2] ?? 'world war 3').toLowerCase(); 7 const base = process.argv[3] ?? 'http://127.0.0.1:8195'; 8 const shot = process.argv[4] ?? '/tmp/lib-run.png'; 9 const secs = Number(process.argv[5] ?? 18); 10 const page = await open(base + '/', { width: 900, height: 1100 }); 11 await sleep(7000); 12 const info = await page.evaluate(`(() => { 13 const all = [...document.querySelectorAll('.pg')]; 14 const hit = all.find((b) => b.dataset.search.includes(${JSON.stringify(want)})); 15 if (hit) hit.click(); 16 return { total: all.length, hit: hit ? hit.querySelector('.pg-t').textContent + ' — ' + hit.querySelector('.pg-s').textContent : null }; 17 })()`); 18 console.log('entrées :', info.total, '; lancé :', info.hit); 19 await sleep(secs * 1000); 20 await page.screenshot(shot); 21 console.log('Capture :', shot); 22 const tape = page.logs.map((l) => l.replace(/^\[\w+\]\s*/, '')).filter((l) => /^TAPE/.test(l)); 23 if (tape.length) console.log('trace chargeur :', tape.length, 'lignes ;', tape.slice(0, 6).join(' | '), '…', tape.slice(-3).join(' | ')); 24 page.close();