audit-mobile-workbench-contacts-resume.mjs 6.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 = 'button') {
  5. const selector = await a.cdp.evaluate(({ text, scope }) => {
  6. document.querySelectorAll('[data-detail-resume-target]').forEach((e) => e.removeAttribute('data-detail-resume-target'));
  7. const matches = [...document.querySelectorAll(scope)].filter((e) => {
  8. const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && (e.textContent || '').replace(/\s+/g, ' ').trim().includes(text);
  9. });
  10. if (matches.length !== 1) throw Error(`目标不唯一:${text}/${matches.length}`);
  11. const e = matches[0]; e.scrollIntoView({ block: 'center' });
  12. const r = e.getBoundingClientRect(), hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2);
  13. if (hit !== e && !e.contains(hit)) throw Error(`目标被遮挡:${text}`);
  14. e.setAttribute('data-detail-resume-target', 'current'); return '[data-detail-resume-target="current"]';
  15. }, { text, scope });
  16. return a.tap(id, selector, text);
  17. }
  18. async function probe(id, path) {
  19. await a.cdp.waitFor((expected) => location.pathname === expected, path, 12000);
  20. await sleep(800);
  21. const shot = await a.snapshot(id);
  22. const data = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 5000), cards: [...document.querySelectorAll('app-m-life-card')].map((e) => ({ name: e.querySelector('.m-name')?.textContent.trim(), buttons: [...e.querySelectorAll('button')].map((b) => b.textContent.trim()) })), controls: [...document.querySelectorAll('button,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), placeholder: e.getAttribute('placeholder') })) }));
  23. fs.writeFileSync(`test-results/mobile-full-audit-20261130/${id}-probe.json`, JSON.stringify(data, null, 2) + '\n', { flag: 'w' });
  24. auditCheck(`${path}页面状态已记录`, data.path === path, { screenshot: shot.id, cards: data.cards.length });
  25. return data;
  26. }
  27. try {
  28. let path = await a.cdp.evaluate(() => location.pathname);
  29. if (path !== '/mobile/workbench') throw Error(`续接需要工作台页面,当前为 ${path}`);
  30. const openDialog = await a.cdp.evaluate(() => document.querySelector('.m-sheet-root[role="dialog"]')?.innerText ?? '');
  31. if (openDialog) {
  32. await a.snapshot('detail-workbench-channel-1-dialog');
  33. fs.writeFileSync('test-results/mobile-full-audit-20261130/detail-workbench-channel-1.txt', openDialog + '\n', { flag: 'w' });
  34. auditCheck('第一个容器通道说明只读弹层', true, { chars: openDialog.length });
  35. await a.tap('detail-workbench-channel-1-close', '.m-sheet-x', '关闭通道说明');
  36. }
  37. const cards = await a.cdp.evaluate(() => [...document.querySelectorAll('app-m-life-card')].map((e) => e.querySelector('.m-name')?.textContent.trim()).filter(Boolean));
  38. for (let index = 1; index < cards.length; index += 1) {
  39. const name = cards[index];
  40. const selector = await a.cdp.evaluate((name) => {
  41. const card = [...document.querySelectorAll('app-m-life-card')].find((e) => e.querySelector('.m-name')?.textContent.trim() === name);
  42. const button = [...(card?.querySelectorAll('button') ?? [])].find((e) => e.textContent.trim() === '通道');
  43. if (!button) throw Error(`找不到${name}的通道按钮`);
  44. button.setAttribute('data-detail-resume-target', 'current'); return '[data-detail-resume-target="current"]';
  45. }, name);
  46. await a.tap(`detail-workbench-channel-${index + 1}`, selector, `${name}的通道说明`);
  47. await a.cdp.waitFor(() => !!document.querySelector('.m-sheet-root[role="dialog"]'), true, 5000);
  48. await sleep(200);
  49. await a.snapshot(`detail-workbench-channel-${index + 1}-dialog`);
  50. const text = await a.cdp.evaluate(() => document.querySelector('.m-sheet-root[role="dialog"]')?.innerText ?? '');
  51. fs.writeFileSync(`test-results/mobile-full-audit-20261130/detail-workbench-channel-${index + 1}.txt`, text + '\n', { flag: 'w' });
  52. auditCheck(`${name}通道说明只读弹层`, !!text, { chars: text.length });
  53. await a.tap(`detail-workbench-channel-${index + 1}-close`, '.m-sheet-x', '关闭通道说明');
  54. }
  55. await a.tap('detail-tab-contacts', '.m-tabbar button:nth-of-type(2)', '通讯录');
  56. const contacts = await probe('detail-contacts-all', '/mobile/contacts');
  57. await tapText('detail-contacts-ai-filter', '数字生命', '.m-segmented button');
  58. await probe('detail-contacts-ai', '/mobile/contacts');
  59. await tapText('detail-contacts-people-filter', '同事', '.m-segmented button');
  60. await probe('detail-contacts-people', '/mobile/contacts');
  61. await tapText('detail-contacts-all-filter', '全部', '.m-segmented button');
  62. await a.fill('detail-contacts-search-no-match', 'app-m-search input', '__AUDIT_NO_MATCH_20261130__');
  63. await probe('detail-contacts-no-match', '/mobile/contacts');
  64. await a.tap('detail-contacts-search-clear', 'app-m-search .m-search-clear', '清除通讯录搜索');
  65. await probe('detail-contacts-restored', '/mobile/contacts');
  66. const colleague = await a.cdp.evaluate(() => {
  67. const section = [...document.querySelectorAll('.m-section')].find((e) => e.innerText.includes('同事 ·'));
  68. const button = section?.querySelector('button.m-row');
  69. if (!button) return null;
  70. button.setAttribute('data-detail-resume-target', 'current'); return button.textContent.trim().replace(/\s+/g, ' ');
  71. });
  72. if (colleague) {
  73. await a.tap('detail-contact-expand-colleague', '[data-detail-resume-target="current"]', '展开同事名下容器');
  74. const expanded = await probe('detail-contacts-colleague-expanded', '/mobile/contacts');
  75. auditCheck('同事行可展开容器列表', expanded.text.includes('数字生命') || expanded.text.includes('暂无可对话的数字生命'), { colleague });
  76. }
  77. await a.checkpoint('已完成工作台所有真实容器的通道说明回读,并检查通讯录分类筛选/搜索/同事展开;未进入会话、未打开充值、未更改设置或服务端数据。证据与动作账本位于test-results/mobile-full-audit-20261130');
  78. console.log(JSON.stringify({ stage: 'workbench_contacts_detail_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length, findings: readAudit().findings.length }));
  79. } catch (error) {
  80. console.error(error);
  81. process.exitCode = 1;
  82. } finally {
  83. a.close();
  84. }