← back to Dw Photo Capture

5x/tools/index-toolbar-click.cjs

36 lines

// index.html: the #homeScreen launcher is a modal overlay that (by design) covers the toolbar, so the
// generic /3x clickthrough times out on every toolbar button. Here: for each engine, for each launcher
// tile and each toolbar button — fresh load, dismiss launcher via "skip →" where needed, click, assert
// no pageerror/console error, Escape, next.
const pw = require(process.env.PW || '/Users/macstudio3/Projects/carnegie-internal/node_modules/playwright');
const BASE = process.env.BASE || 'http://127.0.0.1:9987';
const LAUNCH = { chromium: { args: ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] }, webkit: {}, firefox: { firefoxUserPrefs: { 'media.navigator.streams.fake': true, 'media.navigator.permission.disabled': true } } };
(async () => { let fails = 0;
  for (const e of (process.env.ENGINES || 'chromium,webkit,firefox').split(',')) {
    const b = await pw[e].launch(LAUNCH[e]);
    const ctx = await b.newContext(Object.assign({ httpCredentials: { username: 'admin', password: 'DW2024!' }, viewport: { width: 430, height: 932 } }, e === 'chromium' ? { permissions: ['camera', 'microphone'] } : {}));
    const targets = [['#homeScreen [data-act="add"]', false], ['#homeScreen [data-act="update"]', false], ['#homeScreen [data-act="lookup"]', false], ['#homeScreen [data-act="check"]', false],
      ['#homeBtn', true], ['#scanBtn', true], ['#micBtn', true], ['#camBtn', true], ['#simBtn', true], ['#fbBtn', true], ['#addBtn', true]];
    for (const [sel, skipHome] of targets) {
      const p = await ctx.newPage(); const errs = [];
      p.on('pageerror', x => errs.push('pageerror: ' + x.message));
      p.on('console', m => { if (m.type() === 'error' && !/favicon/.test(m.location().url || '')) errs.push('console: ' + m.text()); });
      p.on('dialog', d => d.dismiss().catch(() => {}));
      p.setDefaultTimeout(6000);
      let res = 'PASS', why = '';
      try {
        await p.goto(BASE + '/', { waitUntil: 'load' });
        if (skipHome) { const s = p.locator('#homeScreen button', { hasText: 'skip' }); if (await s.count()) await s.first().click(); }
        if (!(await p.locator(sel).count())) { res = 'SKIP'; why = 'not present'; }
        else { await p.locator(sel).first().click(); await p.waitForTimeout(1200); await p.keyboard.press('Escape'); await p.waitForTimeout(300); }
      } catch (x) { res = 'FAIL'; why = x.message.split('\n')[0]; }
      if (res === 'PASS' && errs.length) { res = 'FAIL'; why = JSON.stringify(errs); }
      if (res === 'FAIL') fails++;
      console.log(`[${res}] ${e.padEnd(8)} ${sel}${why ? ' — ' + why : ''}`);
      await p.close();
    }
    await b.close();
  }
  console.log(`\nINDEX-TOOLBAR → ${fails} failed`); process.exit(fails ? 1 : 0);
})();