File size: 2,024 Bytes
b1bca40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { chromium } = require('playwright-core');
const fs = require('fs');

const OUT = '/data/shots';
const PAGES = [
  { name: 'shadowbroker', url: 'http://127.0.0.1/', wait: 25000 },
  { name: 'cdhe', url: 'http://127.0.0.1/cdhe/', wait: 8000 },
  { name: 'cdhe_single', url: 'http://127.0.0.1/cdhe/cdhe-monitor.html', wait: 8000 },
  { name: 'worldmonitor', url: 'http://127.0.0.1/wm/', wait: 20000 },
];

(async () => {
  fs.mkdirSync(OUT, { recursive: true });
  const browser = await chromium.launch({
    executablePath: '/data/tools/chrome-headless-shell-linux64/chrome-headless-shell',
    args: ['--no-sandbox', '--disable-dev-shm-usage', '--use-gl=swiftshader',
           '--enable-unsafe-swiftshader', '--disable-gpu-sandbox'],
  });
  const report = [];
  for (const p of PAGES) {
    const ctx = await browser.newContext({ viewport: { width: 1600, height: 1000 },
      deviceScaleFactor: 1, ignoreHTTPSErrors: true });
    const page = await ctx.newPage();
    const errs = [];
    page.on('console', m => { if (m.type() === 'error') errs.push(m.text().slice(0, 200)); });
    page.on('pageerror', e => errs.push('PAGEERROR ' + String(e).slice(0, 200)));
    let status = 0;
    try {
      const resp = await page.goto(p.url, { waitUntil: 'domcontentloaded', timeout: 60000 });
      status = resp ? resp.status() : 0;
      await page.waitForTimeout(p.wait);
      const title = await page.title();
      await page.screenshot({ path: `${OUT}/${p.name}.png`, fullPage: false });
      const txt = (await page.evaluate(() => document.body.innerText)).replace(/\s+/g, ' ').slice(0, 300);
      report.push({ name: p.name, status, title, errors: errs.length, sample: txt,
                    err_samples: errs.slice(0, 3) });
    } catch (e) {
      report.push({ name: p.name, status, error: String(e).slice(0, 300) });
    }
    await ctx.close();
  }
  await browser.close();
  fs.writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 1));
  console.log(JSON.stringify(report, null, 1));
})();