_chat.mjs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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,150)));
  7. p.on('console', m => { if (m.type()==='error') errs.push(m.text().slice(0,150)); });
  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. await p.goto('http://localhost:4200/desktop/chat', { waitUntil: 'networkidle' });
  17. await clear();
  18. await p.waitForTimeout(2500);
  19. const r = await p.evaluate(() => {
  20. const lay = document.querySelector('.conversation-layout');
  21. return {
  22. url: location.pathname,
  23. cols: lay ? getComputedStyle(lay).gridTemplateColumns : null,
  24. colsCount: lay ? getComputedStyle(lay).gridTemplateColumns.split(' ').length : 0,
  25. uiInput: document.querySelectorAll('ui-input').length,
  26. msgBubbles: document.querySelectorAll('app-message-bubble').length,
  27. composer: !!document.querySelector('app-composer'),
  28. overflowX: document.documentElement.scrollWidth > document.documentElement.clientWidth,
  29. };
  30. });
  31. console.log('=== 1440 ==='); console.log(JSON.stringify(r, null, 2));
  32. await p.screenshot({ path: '../../.shots/final-chat-1440.png' });
  33. // 窄窗 1100 验证右栏让位
  34. await p.setViewportSize({ width: 1100, height: 900 });
  35. await p.waitForTimeout(1500);
  36. const n = await p.evaluate(() => {
  37. const lay = document.querySelector('.conversation-layout');
  38. return { cols: getComputedStyle(lay).gridTemplateColumns, railVisible: !!document.querySelector('.rail-col') && getComputedStyle(document.querySelector('.rail-col')).display !== 'none' };
  39. });
  40. console.log('=== 1100(右栏应让位)==='); console.log(JSON.stringify(n));
  41. await p.screenshot({ path: '../../.shots/final-chat-1100.png' });
  42. console.log(errs.length ? '⚠ 错误: '+errs.slice(0,2).join(' | ') : '✅ 无控制台错误');
  43. await b.close();