_final2.mjs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { chromium } from 'playwright';
  2. const b = await chromium.launch({ executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe' });
  3. const p = await (await b.newContext({ viewport: { width: 1440, height: 900 } })).newPage();
  4. const errs = [];
  5. p.on('pageerror', e => errs.push(e.message.slice(0,120)));
  6. p.on('console', m => { if (m.type()==='error') errs.push(m.text().slice(0,120)); });
  7. const clear = () => p.evaluate(() => document.querySelectorAll('vite-error-overlay').forEach(e=>e.remove()));
  8. await p.goto('http://localhost:4200/login', { waitUntil: 'networkidle' });
  9. await clear(); await p.waitForTimeout(800);
  10. const ins = await p.locator('ui-input input').all();
  11. await ins[0].fill('13800138000'); await ins[1].fill('123456');
  12. await p.getByText('登 录', { exact: false }).first().click();
  13. await p.waitForTimeout(3000);
  14. // ① 会话切换验证(核心 bug)
  15. await p.goto('http://localhost:4200/desktop/chat/zhixia', { waitUntil:'networkidle' });
  16. await clear(); await p.waitForTimeout(1800);
  17. const before = await p.locator('.chat-title strong').textContent().catch(()=>'?');
  18. await p.locator('.conv-row').nth(1).click();
  19. await p.waitForTimeout(2000);
  20. const after = await p.locator('.chat-title strong').textContent().catch(()=>'?');
  21. console.log(`① 会话切换: ${before} → ${after} ${before!==after ? '✅ 可切换' : '❌ 仍不能切换'}`);
  22. await p.screenshot({ path: '../../.shots/f2-chat.png' });
  23. // ② 通讯录白框
  24. await p.goto('http://localhost:4200/desktop/contacts', { waitUntil:'networkidle' });
  25. await clear(); await p.waitForTimeout(1800);
  26. const boxW = await p.locator('.search-box').first().evaluate(el => Math.round(el.getBoundingClientRect().width)).catch(()=>0);
  27. console.log(`② 通讯录搜索框宽度: ${boxW}px ${boxW < 400 ? '✅ 已限宽' : '❌ 仍撑满'}`);
  28. await p.screenshot({ path: '../../.shots/f2-contacts.png' });
  29. // ③ 导航选中态(无竖条) + 折叠
  30. await p.goto('http://localhost:4200/desktop/workbench', { waitUntil:'networkidle' });
  31. await clear(); await p.waitForTimeout(1500);
  32. const shadow = await p.locator('.nav-link.active').first().evaluate(el => getComputedStyle(el).boxShadow).catch(()=>'none');
  33. console.log(`③ 导航选中态 box-shadow: ${shadow} ${shadow==='none' ? '✅ 无竖条' : '❌ 仍有'}`);
  34. await p.locator('.collapse-btn').click();
  35. await p.waitForTimeout(1200);
  36. const navW = await p.locator('.sidebar').evaluate(el => Math.round(el.getBoundingClientRect().width));
  37. console.log(`④ 折叠后侧栏宽: ${navW}px ${navW < 100 ? '✅ 已折叠' : '❌ 未折叠'}`);
  38. await p.screenshot({ path: '../../.shots/f2-nav-collapsed.png' });
  39. // ⑤ 我的页 PC 布局
  40. await p.goto('http://localhost:4200/desktop/mine', { waitUntil:'networkidle' });
  41. await clear(); await p.waitForTimeout(1800);
  42. await p.screenshot({ path: '../../.shots/f2-mine.png', fullPage: true });
  43. console.log(errs.length ? '⚠ 错误: '+errs.slice(0,2).join(' | ') : '✅ 无控制台错误');
  44. await b.close();