_final.mjs 1.7 KB

123456789101112131415161718192021222324252627282930
  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. await p.goto('http://localhost:4200/', { waitUntil: 'domcontentloaded' });
  9. await p.evaluate(() => { document.querySelectorAll('vite-error-overlay').forEach(e => e.remove()); });
  10. await p.goto('http://localhost:4200/login', { waitUntil: 'networkidle' });
  11. await p.evaluate(() => { document.querySelectorAll('vite-error-overlay').forEach(e => e.remove()); });
  12. await p.waitForTimeout(700);
  13. await p.fill('input[type="tel"]', '13800138000');
  14. await p.fill('input[type="text"][maxlength="6"]', '123456');
  15. await p.click('button[type="submit"]');
  16. await p.waitForTimeout(3000);
  17. await p.goto('http://localhost:4200/desktop/workbench', { waitUntil: 'networkidle' });
  18. await p.waitForTimeout(2500);
  19. const r = await p.evaluate(() => ({
  20. demoStrip: !!document.querySelector('.demo-strip'),
  21. demoText: /演示数据|未连接真实服务/.test(document.body.innerText),
  22. uiCards: document.querySelectorAll('ui-card').length,
  23. uiStats: document.querySelectorAll('ui-statistic').length,
  24. uiProgress: document.querySelectorAll('ui-progress').length,
  25. overflowX: document.documentElement.scrollWidth > document.documentElement.clientWidth,
  26. }));
  27. console.log(JSON.stringify(r, null, 2));
  28. await p.screenshot({ path: '../../.shots/final-workbench-1440.png' });
  29. console.log(errs.length ? '⚠ 错误: '+errs.slice(0,2).join(' | ') : '✅ 无控制台错误');
  30. await b.close();