|
| 1 | +// Click every button/chip/tab, move every slider, open every <details>, verify the PNG export downloads; report errors per widget. |
| 2 | +const { chromium } = require('playwright'); |
| 3 | +const base = 'http://127.0.0.1:8765/'; |
| 4 | +const widgets = ['oco/widgets/spectra-explorer.html','oco/widgets/footprint-scale.html','oco/widgets/photon-path.html', |
| 5 | + 'sif/widgets/fraunhofer-explorer.html?data=/sif/data/solar_757_771nm.json','sif/widgets/sif-map.html','sif/widgets/resolution-explorer.html', |
| 6 | + 'sif/widgets/spectral-explorer.html','sif/widgets/albedo-explorer.html','sif/widgets/canopy-builder.html','sif/widgets/fluorescence-spectrum.html']; |
| 7 | +(async () => { |
| 8 | + const browser = await chromium.launch({ args: ['--no-sandbox'] }); |
| 9 | + for (const w of widgets) { |
| 10 | + const ctx = await browser.newContext({ acceptDownloads: true, viewport: { width: 890, height: 1400 } }); const page = await ctx.newPage(); const errs = []; |
| 11 | + page.on('pageerror', e => errs.push('pageerror: ' + String(e.message).slice(0, 140))); page.on('console', m => { if (m.type() === 'error') errs.push('console: ' + m.text().slice(0, 140)); }); |
| 12 | + await page.goto(base + w, { waitUntil: 'networkidle' }); await page.waitForTimeout(800); |
| 13 | + const before = await page.evaluate(() => document.querySelector('canvas') ? document.querySelector('canvas').toDataURL().length : 0); |
| 14 | + // buttons (skip the PNG export, tested separately) |
| 15 | + const buttons = await page.$$('button, .chip, .tab, [role=button], select'); |
| 16 | + let nb = 0, changed = 0; |
| 17 | + for (const b of buttons) { |
| 18 | + const txt = ((await b.textContent()) || '').trim(); if (/PNG/.test(txt)) continue; |
| 19 | + const tag = await b.evaluate(e => e.tagName); |
| 20 | + if (tag === 'SELECT') { const opts = await b.$$('option'); if (opts.length > 1) { await b.selectOption({ index: 1 }); nb++; } continue; } |
| 21 | + try { await b.click({ timeout: 2000 }); nb++; await page.waitForTimeout(120); } catch (e) { errs.push('click failed: ' + txt.slice(0, 30)); } |
| 22 | + const after = await page.evaluate(() => document.querySelector('canvas') ? document.querySelector('canvas').toDataURL().length : 0); if (after !== before) changed++; |
| 23 | + } |
| 24 | + // sliders |
| 25 | + const sliders = await page.$$('input[type=range]'); let ns = 0; |
| 26 | + for (const s of sliders) { const mx = await s.getAttribute('max'), mn = await s.getAttribute('min'); for (const v of [mx, mn]) { await s.evaluate((el, val) => { el.value = val; el.dispatchEvent(new Event('input', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true })); }, v); await page.waitForTimeout(80); } ns++; } |
| 27 | + // details |
| 28 | + const det = await page.$$('details'); for (const d of det) await d.evaluate(e => e.open = true); |
| 29 | + // checkboxes / radios |
| 30 | + const cbs = await page.$$('input[type=checkbox], input[type=radio]'); for (const c of cbs) { try { await c.click({ timeout: 1000 }); } catch (e) { errs.push('checkbox click failed'); } } |
| 31 | + await page.waitForTimeout(300); |
| 32 | + // PNG export must trigger a download |
| 33 | + let dl = 'no PNG button'; |
| 34 | + const png = await page.$('button:has-text("PNG")'); |
| 35 | + if (png) { try { const [d] = await Promise.all([page.waitForEvent('download', { timeout: 6000 }), png.click()]); dl = `download ok (${d.suggestedFilename()})`; } catch (e) { dl = 'DOWNLOAD FAILED'; } } |
| 36 | + console.log(JSON.stringify({ widget: w.split('?')[0].split('/').pop(), buttons: nb, canvas_redraws: changed, sliders: ns, details: det.length, toggles: cbs.length, export: dl, errors: [...new Set(errs)].slice(0, 4) })); |
| 37 | + await ctx.close(); |
| 38 | + } |
| 39 | + await browser.close(); |
| 40 | +})(); |
0 commit comments