.tmp-routes.mjs 1.5 KB

123456789101112131415161718192021222324
  1. import { chromium } from 'playwright';
  2. const base = 'http://localhost:4200';
  3. const b = await chromium.launch({ channel: 'msedge' });
  4. const ctx = await b.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true,
  5. userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148 Safari/604.1' });
  6. const p = await ctx.newPage();
  7. const errs = [];
  8. p.on('pageerror', e => errs.push(e.message));
  9. p.on('console', m => { if (m.type() === 'error') errs.push(m.text().slice(0, 140)); });
  10. await p.goto(base + '/login'); await p.waitForTimeout(1000);
  11. await p.locator('input').nth(0).fill('13800000000');
  12. await p.getByRole('button', { name: /获取验证码/ }).first().click(); await p.waitForTimeout(400);
  13. await p.locator('input').nth(1).fill('123456');
  14. await p.getByRole('button', { name: /^登\s*录$/ }).first().click(); await p.waitForTimeout(3500);
  15. const routes = ['chat-index', 'contacts', 'projects', 'tasks', 'events', 'workbench', 'deliverables', 'mine'];
  16. const out = [];
  17. for (const r of routes) {
  18. await p.goto(`${base}/mobile/${r}`); await p.waitForTimeout(1800);
  19. const info = await p.evaluate(() => ({ len: document.body.innerText.trim().length, over: document.documentElement.scrollWidth > innerWidth + 1, text: document.body.innerText.slice(0, 40).replace(/\n/g, ' ') }));
  20. await p.screenshot({ path: `.tmp-shots/${r}.png` });
  21. out.push([r, info.len, info.over, info.text]);
  22. }
  23. console.log(JSON.stringify({ out, errs: [...new Set(errs)].slice(0, 8) }, null, 1));
  24. await b.close();