import fs from 'node:fs'; import { connectAudit, readAudit, sleep, auditCheck } from './lib/mobile-full-audit.mjs'; const a = await connectAudit(); async function buttonByText(id, text, scope = 'button', occurrence = 0) { const selector = await a.cdp.evaluate(({ text, scope }) => { document.querySelectorAll('[data-secondary-audit-target]').forEach((e) => e.removeAttribute('data-secondary-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}`); matches[occurrence].scrollIntoView({ block: 'center' }); const r = matches[occurrence].getBoundingClientRect(); const hit = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); if (hit !== matches[occurrence] && !matches[occurrence].contains(hit)) throw Error(`目标被其他界面遮挡:${text}`); matches[occurrence].setAttribute('data-secondary-audit-target', 'current'); return '[data-secondary-audit-target="current"]'; }, { text, scope }); return a.tap(id, selector, text); } async function settled(id, expectedPath, wait = 1000) { await a.cdp.waitFor((path) => location.pathname === path, expectedPath, 15000); await sleep(wait); const shot = await a.snapshot(id); const probe = await a.cdp.evaluate(() => ({ path: location.pathname, heading: document.querySelector('.m-title-main')?.textContent.trim() || document.querySelector('h1')?.textContent.trim() || '', text: document.body.innerText.slice(0, 5000), controls: [...document.querySelectorAll('button,a,input,textarea,[role="button"]')] .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) => ({ tag: e.tagName, text: e.tagName === 'INPUT' ? '' : e.textContent.trim().replace(/\s+/g, ' ').slice(0, 120), label: e.getAttribute('aria-label'), href: e.getAttribute('href'), class: String(e.className).slice(0, 100), disabled: !!e.disabled })) })); fs.writeFileSync(`test-results/mobile-full-audit-20261130/${id}-probe.json`, JSON.stringify(probe, null, 2) + '\n', { flag: 'w' }); auditCheck(`${expectedPath}页面到达`, probe.path === expectedPath, { screenshot: shot.id, heading: probe.heading }); return probe; } try { await a.tap('secondary-tab-mine', '.m-tabbar button:nth-of-type(4)', '进入我的'); await settled('secondary-mine-settled', '/mobile/mine'); await buttonByText('secondary-my-containers-open', '我的容器', '.m-plan-btn'); const containers = await settled('secondary-my-containers-settled', '/mobile/my-containers', 1800); const access = containers.controls.find((x) => x.text.includes('查看接入信息')); auditCheck('我的容器显示真实列表或空态', containers.text.includes('我的容器') || containers.text.includes('还没有容器') || containers.text.includes('正在加载'), { controls: containers.controls.length }); if (access) { await buttonByText('secondary-container-access-open', '查看接入信息', 'button.container-btn', 0); await settled('secondary-plan-access-settled', '/mobile/plan-access'); await a.back('secondary-plan-access-back'); await a.cdp.waitFor(() => location.pathname === '/mobile/my-containers', true, 10000); } await buttonByText('secondary-plans-open-from-containers', '查看套餐', '.quota-btn, .empty-btn'); await settled('secondary-plans-settled', '/mobile/plans', 1200); await a.back('secondary-plans-back'); await a.cdp.waitFor(() => location.pathname === '/mobile/my-containers', true, 10000); await a.back('secondary-containers-back'); await a.cdp.waitFor(() => location.pathname === '/mobile/mine', true, 10000); await buttonByText('secondary-about-open', '关于与版本', '.m-row'); await sleep(1800); await a.snapshot('secondary-about-after'); const about = await a.cdp.evaluate(() => ({ path: location.pathname, text: document.body.innerText.slice(0, 3000), dialogs: [...document.querySelectorAll('[role="dialog"]')].map((e) => e.innerText.slice(0, 1000)) })); fs.writeFileSync('test-results/mobile-full-audit-20261130/secondary-about-probe.json', JSON.stringify(about, null, 2) + '\n', { flag: 'w' }); auditCheck('关于与版本点击后仍在设置页或显示更新反馈', about.path === '/mobile/mine' && (about.text.includes('关于与版本') || about.dialogs.length >= 0), { screenshot: 'secondary-about-after' }); await a.cdp.evaluate(() => document.querySelector('.m-update-dialog button,[aria-label="关闭"]')?.click()); await a.checkpoint('已真机只读审计我的容器、容器接入信息(若有)、套餐页与关于版本;未申请、未充值、未退出、未创建。证据与动作账本位于test-results/mobile-full-audit-20261130'); console.log(JSON.stringify({ stage: 'secondary_account_pages_complete', screenshots: readAudit().screenshots.length, actions: Object.keys(readAudit().actions).length })); } catch (error) { console.error(error); process.exitCode = 1; } finally { a.close(); }