audit-mobile-secondary-resume.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import fs from 'node:fs';
  2. import { connectAudit, readAudit, sleep, auditCheck } from './lib/mobile-full-audit.mjs';
  3. const a = await connectAudit();
  4. async function tapText(id, text, scope) {
  5. const selector = await a.cdp.evaluate(({ text, scope }) => {
  6. document.querySelectorAll('[data-secondary-audit-target]').forEach((e) => e.removeAttribute('data-secondary-audit-target'));
  7. const matches = [...document.querySelectorAll(scope)].filter((e) => {
  8. const r = e.getBoundingClientRect();
  9. return r.width > 0 && r.height > 0 && (e.textContent || '').replace(/\s+/g, ' ').trim().includes(text);
  10. });
  11. if (matches.length !== 1) throw Error(`目标不唯一:${text}/${matches.length}`);
  12. const e = matches[0]; e.scrollIntoView({ block: 'center' });
  13. const r = e.getBoundingClientRect(), hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2);
  14. if (hit !== e && !e.contains(hit)) throw Error(`目标被遮挡:${text}`);
  15. e.setAttribute('data-secondary-audit-target', 'current');
  16. return '[data-secondary-audit-target="current"]';
  17. }, { text, scope });
  18. return a.tap(id, selector, text);
  19. }
  20. async function expect(path, shotId, probeId) {
  21. await a.cdp.waitFor((target) => location.pathname === target, path, 10000);
  22. await sleep(1000);
  23. const shot = await a.snapshot(shotId);
  24. const probe = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 5000), dialogs: [...document.querySelectorAll('[role="dialog"]')].map((e) => e.innerText.slice(0, 1000)), controls: [...document.querySelectorAll('button,a,input')].filter((e) => { const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && r.x >= 0 && r.right <= innerWidth + 1 && r.y >= 0 && r.bottom <= innerHeight + 1; }).map((e) => ({ text: e.tagName === 'INPUT' ? '' : e.textContent.trim().replace(/\s+/g, ' ').slice(0, 100), label: e.getAttribute('aria-label'), cls: String(e.className).slice(0, 80) })) }));
  25. fs.writeFileSync(`test-results/mobile-full-audit-20261130/${probeId}.json`, JSON.stringify(probe, null, 2) + '\n', { flag: 'w' });
  26. auditCheck(`${path}只读页面到达`, probe.path === path, { screenshot: shot.id, dialogs: probe.dialogs.length });
  27. return probe;
  28. }
  29. try {
  30. let path = await a.cdp.evaluate(() => location.pathname);
  31. if (path === '/plans') {
  32. await expect('/plans', 'secondary-plans-settled', 'secondary-plans-probe');
  33. await a.back('secondary-plans-back');
  34. path = await a.cdp.evaluate(() => location.pathname);
  35. }
  36. if (path === '/mobile/my-containers') {
  37. await a.back('secondary-containers-back');
  38. path = await a.cdp.evaluate(() => location.pathname);
  39. }
  40. if (path !== '/mobile/mine') throw Error(`期望返回我的页面,当前为 ${path}`);
  41. await a.snapshot('secondary-mine-returned');
  42. await tapText('secondary-about-open', '关于与版本', '.m-row');
  43. await sleep(1600);
  44. const about = await expect('/mobile/mine', 'secondary-about-after', 'secondary-about-probe');
  45. auditCheck('关于与版本入口显示当前版本或更新结果', about.text.includes('关于与版本') && /v\d|版本|检查/.test(about.text), { dialogCount: about.dialogs.length });
  46. await a.checkpoint('已真机只读审计我的容器列表、首个容器接入信息、顶层套餐页及关于与版本入口;未申请、未续费、未充值、未退出或创建。路由探针修正记录保留。证据与动作账本位于test-results/mobile-full-audit-20261130');
  47. console.log(JSON.stringify({ stage: 'secondary_account_pages_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length }));
  48. } catch (error) {
  49. console.error(error);
  50. process.exitCode = 1;
  51. } finally {
  52. a.close();
  53. }