| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import fs from 'node:fs';
- import { connectAudit, readAudit, sleep, auditCheck } from './lib/mobile-full-audit.mjs';
- const a = await connectAudit();
- async function tapText(id, text, scope = 'button', occurrence = 0) {
- const selector = await a.cdp.evaluate(({ text, scope, occurrence }) => {
- document.querySelectorAll('[data-detail-audit-target]').forEach((e) => e.removeAttribute('data-detail-audit-target'));
- const matches = [...document.querySelectorAll(scope)].filter((e) => {
- const r = e.getBoundingClientRect();
- return r.width > 0 && r.height > 0 && (e.textContent || '').replace(/\s+/g, ' ').trim().includes(text);
- });
- if (!matches[occurrence]) throw Error(`目标不可见:${text}/${matches.length}`);
- const e = matches[occurrence]; e.scrollIntoView({ block: 'center' });
- const r = e.getBoundingClientRect(), hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2);
- if (hit !== e && !e.contains(hit)) throw Error(`目标被遮挡:${text}`);
- e.setAttribute('data-detail-audit-target', 'current');
- return '[data-detail-audit-target="current"]';
- }, { text, scope, occurrence });
- return a.tap(id, selector, text);
- }
- async function pageProbe(id, path) {
- await a.cdp.waitFor((expected) => location.pathname === expected, path, 12000);
- await sleep(900);
- const shot = await a.snapshot(id);
- const probe = 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(), status: e.querySelector('app-m-badge')?.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, 120), placeholder: e.getAttribute('placeholder'), cls: String(e.className).slice(0, 100), selected: e.getAttribute('aria-selected') }))
- }));
- fs.writeFileSync(`test-results/mobile-full-audit-20261130/${id}-probe.json`, JSON.stringify(probe, null, 2) + '\n', { flag: 'w' });
- auditCheck(`${path}页面状态已记录`, probe.path === path, { screenshot: shot.id, cards: probe.cards.length });
- return probe;
- }
- try {
- const current = await a.cdp.evaluate(() => location.pathname);
- if (current !== '/mobile/mine') throw Error(`当前页面不是我的:${current}`);
- await a.tap('detail-tab-workbench', '.m-tabbar button:nth-of-type(3)', '工作台');
- const initial = await pageProbe('detail-workbench-initial', '/mobile/workbench');
- await tapText('detail-workbench-online-filter', '在线', '.m-segmented button');
- const online = await pageProbe('detail-workbench-online', '/mobile/workbench');
- await tapText('detail-workbench-offline-filter', '离线', '.m-segmented button');
- const offline = await pageProbe('detail-workbench-offline', '/mobile/workbench');
- await tapText('detail-workbench-all-filter', '全部', '.m-segmented button');
- await a.fill('detail-workbench-search-no-match', 'app-m-search input', '__AUDIT_NO_MATCH_20261130__');
- await pageProbe('detail-workbench-no-match', '/mobile/workbench');
- await a.tap('detail-workbench-search-clear', 'app-m-search .m-search-clear', '清除工作台搜索');
- await pageProbe('detail-workbench-restored', '/mobile/workbench');
- auditCheck('工作台在线/离线筛选与搜索可恢复', online.cards.length + offline.cards.length >= initial.cards.length && initial.cards.length > 0, { total: initial.cards.length, online: online.cards.length, offline: offline.cards.length });
- for (let index = 0; index < initial.cards.length; index += 1) {
- const name = initial.cards[index].name;
- const selector = await a.cdp.evaluate((name) => {
- document.querySelectorAll('[data-detail-audit-target]').forEach((e) => e.removeAttribute('data-detail-audit-target'));
- const card = [...document.querySelectorAll('app-m-life-card')].find((e) => e.querySelector('.m-name')?.textContent.trim() === name);
- const button = [...(card?.querySelectorAll('button') ?? [])].find((e) => e.textContent.trim() === '通道');
- if (!button) throw Error(`找不到${name}的通道按钮`);
- button.setAttribute('data-detail-audit-target', 'current');
- return '[data-detail-audit-target="current"]';
- }, name);
- await a.tap(`detail-workbench-channel-${index + 1}`, selector, `${name}的通道说明`);
- await a.cdp.waitFor(() => !!document.querySelector('.m-sheet-root[role="dialog"]'), true, 5000);
- await sleep(250);
- await a.snapshot(`detail-workbench-channel-${index + 1}-dialog`);
- const text = await a.cdp.evaluate(() => document.querySelector('.m-sheet-root[role="dialog"]')?.innerText ?? '');
- fs.writeFileSync(`test-results/mobile-full-audit-20261130/detail-workbench-channel-${index + 1}.txt`, text + '\n', { flag: 'w' });
- auditCheck(`${name}通道说明只读弹层`, !!text, { chars: text.length });
- await a.tap(`detail-workbench-channel-${index + 1}-close`, '.m-sheet-x', '关闭通道说明');
- }
- await a.tap('detail-tab-contacts', '.m-tabbar button:nth-of-type(2)', '通讯录');
- const contacts = await pageProbe('detail-contacts-all', '/mobile/contacts');
- await tapText('detail-contacts-ai-filter', '数字生命', '.m-segmented button');
- await pageProbe('detail-contacts-ai', '/mobile/contacts');
- await tapText('detail-contacts-people-filter', '同事', '.m-segmented button');
- await pageProbe('detail-contacts-people', '/mobile/contacts');
- await tapText('detail-contacts-all-filter', '全部', '.m-segmented button');
- await a.fill('detail-contacts-search-no-match', 'app-m-search input', '__AUDIT_NO_MATCH_20261130__');
- await pageProbe('detail-contacts-no-match', '/mobile/contacts');
- await a.tap('detail-contacts-search-clear', 'app-m-search .m-search-clear', '清除通讯录搜索');
- await pageProbe('detail-contacts-restored', '/mobile/contacts');
- auditCheck('通讯录三类筛选与搜索可恢复', contacts.path === '/mobile/contacts', { controls: contacts.controls.length });
- const colleague = await a.cdp.evaluate(() => {
- const section = [...document.querySelectorAll('.m-section')].find((e) => e.innerText.includes('同事 ·'));
- const button = section?.querySelector('button.m-row');
- if (!button) return null;
- button.setAttribute('data-detail-audit-target', 'current');
- return button.textContent.trim().replace(/\s+/g, ' ');
- });
- if (colleague) {
- await a.tap('detail-contact-expand-colleague', '[data-detail-audit-target="current"]', '展开同事名下容器');
- const expanded = await pageProbe('detail-contacts-colleague-expanded', '/mobile/contacts');
- auditCheck('同事行可展开容器列表', expanded.text.includes('数字生命') || expanded.text.includes('暂无可对话的数字生命'), { colleague });
- }
- await a.checkpoint('已真机检查工作台在线/离线筛选、搜索、全部容器通道说明弹层,以及通讯录分类筛选/搜索/同事展开;未进入会话、未打开充值、未更改设置或服务端数据。证据与动作账本位于test-results/mobile-full-audit-20261130');
- console.log(JSON.stringify({ stage: 'workbench_contacts_detail_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length, findings: readAudit().findings.length }));
- } catch (error) {
- console.error(error);
- process.exitCode = 1;
- } finally {
- a.close();
- }
|