_verify.mjs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { chromium } from 'playwright';
  2. const browser = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe' });
  3. async function login(p) {
  4. await p.goto('http://localhost:4200/login', { waitUntil: 'networkidle' });
  5. await p.waitForTimeout(600);
  6. await p.fill('input[type="tel"]', '13800138000');
  7. await p.fill('input[type="text"][maxlength="6"]', '123456');
  8. await p.click('button[type="submit"]');
  9. await p.waitForTimeout(3000);
  10. }
  11. // 全新 context = 无缓存,Cache-Control: no-store 双保险
  12. const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 }, bypassCSP: true });
  13. const p = await ctx.newPage();
  14. await p.route('**/*', r => r.continue());
  15. const errs = [];
  16. p.on('pageerror', e => errs.push(e.message.slice(0,120)));
  17. p.on('console', m => { if (m.type()==='error') errs.push(m.text().slice(0,120)); });
  18. await login(p);
  19. await p.goto('http://localhost:4200/desktop/workbench', { waitUntil: 'networkidle' });
  20. await p.waitForTimeout(2500);
  21. const probe = await p.evaluate(() => ({
  22. url: location.pathname,
  23. h1: document.querySelector('h1')?.textContent?.trim(),
  24. stats: document.querySelectorAll('ui-statistic').length,
  25. cards: document.querySelectorAll('ui-card').length,
  26. oldCards: document.querySelectorAll('.agent-card').length,
  27. oldMetric: document.querySelectorAll('.bar').length,
  28. demoWord: document.body.innerText.includes('演示数据'),
  29. overflowX: document.documentElement.scrollWidth > document.documentElement.clientWidth,
  30. scrollW: document.documentElement.scrollWidth,
  31. clientW: document.documentElement.clientWidth,
  32. }));
  33. console.log('=== 工作台(1440×900, 无缓存) ===');
  34. console.log(JSON.stringify(probe, null, 2));
  35. if (errs.length) console.log('⚠ 控制台错误:', errs.slice(0,3));
  36. else console.log('✅ 无控制台错误');
  37. await p.screenshot({ path: '../../.shots/dk-workbench-NEW.png' });
  38. // 宽屏 1920 验证流动布局
  39. await p.setViewportSize({ width: 1920, height: 1080 });
  40. await p.waitForTimeout(1200);
  41. const wide = await p.evaluate(() => ({
  42. cols: getComputedStyle(document.querySelector('.grid')).gridTemplateColumns,
  43. scrollW: document.documentElement.scrollWidth,
  44. clientW: document.documentElement.clientWidth,
  45. }));
  46. console.log('\n=== 1920×1080 流动布局 ===');
  47. console.log('卡片网格列:', wide.cols);
  48. await p.screenshot({ path: '../../.shots/dk-workbench-1920.png' });
  49. // 窄窗 1100 验证降级
  50. await p.setViewportSize({ width: 1100, height: 900 });
  51. await p.waitForTimeout(1200);
  52. await p.screenshot({ path: '../../.shots/dk-workbench-1100.png' });
  53. console.log('\n✅ 截图已出:dk-workbench-NEW / -1920 / -1100');
  54. await browser.close();