| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import fs from 'node:fs';
- import {connectAudit,readAudit,updateAudit,auditCheck,auditFinding,auditDirectory,sleep} from './lib/mobile-full-audit.mjs';
- const a=await connectAudit();
- const resume=process.argv.find(x=>x.startsWith('--resume='))?.slice(9);
- if(resume&&resume!=='tabs')throw Error('不支持的恢复位置');
- try{
- const id=await a.cdp.evaluate(()=>{try{return JSON.parse(localStorage.getItem('fmode_me')||'null')?.id}catch{return null}});
- if(id!==readAudit().identity?.me?.id)throw Error('当前账号变化,停止业务页面操作');
- const permission=()=>a.adb(['shell','dumpsys','package',a.session.packageId]).split(/\r?\n/).filter(x=>/android.permission.POST_NOTIFICATIONS:/.test(x)).map(x=>x.trim());
- const before=permission();
- if(!resume){
- if(await a.cdp.evaluate(()=>!!document.querySelector('.pg-root'))){
- const shot=await a.snapshot('notification-guide-initial');
- const dom=JSON.parse(fs.readFileSync(shot.dom,'utf8'));
- const close=dom.controls.find(x=>x.label==='关闭'&&x.classes.includes('pg-close'));
- if(close&&(close.rect.width<44||close.rect.height<44))auditFinding({id:'TOUCH-001',priority:'P2',area:'通知引导',title:'关闭按钮触控范围偏小',actual:`${close.rect.width}×${close.rect.height} CSS像素`,expected:'至少44×44 CSS像素',screenshots:[shot.id],recommendation:'后续统一扩大点击热区,保留当前视觉图标尺寸'});
- await a.tap('notification-guide-close-x','.pg-root .pg-close','关闭消息提醒说明,不改变系统权限');
- }
- auditCheck('关闭引导保持系统通知权限不变',JSON.stringify(before)===JSON.stringify(permission()),{before,after:permission()});
- await a.snapshot('messages-main');
- await a.tapText('messages-project-filter','项目','.m-seg-row');
- await a.tapText('messages-project-form-open','新建项目','.m-msgws-actions');
- auditCheck('空项目名创建禁用',await a.cdp.evaluate(()=>document.querySelector('.m-msgws-ok')?.disabled));
- await a.tapText('messages-project-form-cancel','取消','.m-msgws-form');
- await a.tapText('messages-all-filter','全部','.m-seg-row');
- await a.tap('messages-search-focus','app-m-search input','搜索会话');
- await a.fill('messages-search-no-match','app-m-search input','__AUDIT_NO_MATCH_20261130__');
- await a.tap('messages-search-clear','app-m-search .m-search-clear','清除搜索');
- if(/mInputShown=true|isInputViewShown=true/.test(a.adb(['shell','dumpsys','input_method'])))await a.back('messages-search-keyboard-back');
- await a.snapshot('messages-search-restored');
- await a.tap('navigation-drawer-open','[aria-label="打开导航"]','打开导航');
- await a.snapshot('navigation-drawer-full');
- const menus=await a.cdp.evaluate(()=>[...document.querySelectorAll('.m-drawer.show 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=>({text:e.textContent.trim().replace(/\s+/g,' '),label:e.getAttribute('aria-label'),class:e.className})));
- fs.writeFileSync(auditDirectory+'/drawer-controls.json',JSON.stringify(menus,null,2)+'\n',{flag:'wx'});
- await a.tap('navigation-drawer-mask-close','app-m-drawer .m-mask.show','关闭导航遮罩');
- }else{
- if(!await a.cdp.evaluate(()=>!!document.querySelector('.m-drawer.show')))throw Error('当前不在待恢复抽屉状态');
- updateAudit(s=>{const old=s.actions['navigation-drawer-mask-close'];if(old?.status!=='uncertain')throw Error('旧动作状态不匹配');old.statusHistory=[{status:'uncertain',reason:'遮罩中心在抽屉下方;测试在命中检查时停止,未派发触摸'}];old.status='not_executed_precondition';old.reconciledAt=new Date().toISOString()});
- await a.tap('navigation-drawer-mask-edge-close','app-m-drawer .m-mask.show','点击抽屉外露遮罩关闭');
- }
- for(const [route,index] of [['contacts',2],['workbench',3],['mine',4],['messages',1]]){
- await a.tap('tab-'+route,'.m-tabbar button:nth-of-type('+index+')','底栏进入'+route);
- await a.cdp.waitFor(r=>location.pathname==='/mobile/'+r,route,15000);
- await sleep(1200);await a.snapshot(route+'-settled');
- const probe=await a.cdp.evaluate(()=>({path:location.pathname,heading:document.querySelector('.m-title-main')?.textContent.trim(),text:document.body.innerText.slice(0,2600),buttons:[...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}).map(e=>({tag:e.tagName,text:e.tagName==='INPUT'?'':e.textContent.trim().replace(/\s+/g,' ').slice(0,80),label:e.getAttribute('aria-label'),class:String(e.className).slice(0,100),placeholder:e.getAttribute('placeholder'),href:e.getAttribute('href')}))}));
- probe.text=probe.text.replace(/r:[A-Za-z0-9_+%/=.-]{8,}/g,'[凭证已遮盖]');
- fs.writeFileSync(auditDirectory+'/'+route+'-probe.json',JSON.stringify(probe,null,2)+'\n',{flag:'wx'});
- auditCheck('底栏'+route+'路由到达',probe.path==='/mobile/'+route,{heading:probe.heading});
- }
- updateAudit(s=>{s.stage='navigation_basics_complete';s.notificationPermissionBaseline=before});
- await a.checkpoint('登录后通知引导关闭/权限保持、会话筛选与搜索、项目空表单取消、导航抽屉和四个底栏页面均已真机点击并截图;未创建项目或发送消息。接下来继续页面二级入口、容器与设置细项');
- console.log(JSON.stringify({stage:'navigation_basics_complete',screenshots:readAudit().screenshots.length,findings:readAudit().findings.length}));
- }catch(error){updateAudit(s=>{s.failures.push({stage:'navigation_audit',message:error.message,at:new Date().toISOString()});s.stage='navigation_audit_needs_readback'});console.error(error);process.exitCode=1}finally{a.close()}
|