_all.mjs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { chromium } from 'playwright';
  2. const b = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe' });
  3. const ctx = await b.newContext({ viewport: { width: 1440, height: 900 } });
  4. const p = await ctx.newPage();
  5. const errs = [];
  6. p.on('pageerror', e => errs.push(e.message.slice(0,120)));
  7. p.on('console', m => { if (m.type()==='error') errs.push(m.text().slice(0,120)); });
  8. const clear = () => p.evaluate(() => document.querySelectorAll('vite-error-overlay').forEach(e=>e.remove()));
  9. await p.goto('http://localhost:4200/login', { waitUntil: 'networkidle' });
  10. await clear();
  11. await p.waitForTimeout(600);
  12. await p.fill('input[type="tel"]', '13800138000');
  13. await p.fill('input[type="text"][maxlength="6"]', '123456');
  14. await p.click('button[type="submit"]');
  15. await p.waitForTimeout(3000);
  16. const pages = [
  17. ['workbench','/desktop/workbench'], ['chat','/desktop/chat'], ['contacts','/desktop/contacts'],
  18. ['projects','/desktop/projects'], ['events','/desktop/events'], ['tasks','/desktop/tasks'],
  19. ['deliverables','/desktop/deliverables'], ['agent','/desktop/agent/zhixia'], ['mine','/desktop/mine'],
  20. ];
  21. for (const [name, path] of pages) {
  22. await p.goto('http://localhost:4200' + path, { waitUntil: 'networkidle' });
  23. await clear();
  24. await p.waitForTimeout(1800);
  25. await p.screenshot({ path: `../../.shots/dk-${name}.png` });
  26. const r = await p.evaluate(() => ({
  27. overflow: document.documentElement.scrollWidth > document.documentElement.clientWidth,
  28. demo: /演示数据|未连接真实服务/.test(document.body.innerText),
  29. h1: document.querySelector('h1')?.textContent?.trim()?.slice(0,10),
  30. }));
  31. console.log(` ${name.padEnd(13)} h1=${(r.h1||'-').padEnd(10)} 溢出=${r.overflow?'⚠️是':'否'} demo文案=${r.demo?'⚠️有':'无'}`);
  32. }
  33. console.log(errs.length ? '\n⚠ 错误: '+errs.slice(0,3).join(' | ') : '\n✅ 全部页面无控制台错误');
  34. await b.close();