AI_UIAutomation/scripts/probe-tap.ts

9 lines
991 B
TypeScript

import { createDriver } from '../drivers/factory';
const sleep=(ms:number)=>new Promise(r=>setTimeout(r,ms));
const dump=async(d:any):Promise<string[]>=>[...new Set((Array.from((await d.getSource()).matchAll(/text="([^"]+)"/g)) as any[]).map(m=>m[1]).filter((t:string)=>t.trim()&&t.length<40))].slice(0,20) as string[];
(async()=>{const d=createDriver();await d.createSession();try{
const T=process.env.TAP||'Connect Device';
for(const t of [T,'Connect device']){const b=await d.findElementRaw('-android uiautomator',`new UiSelector().text("${t}")`).catch(()=>null);if(b){await d.tapElement(b);console.log('点了 '+t);break;}}
for(let i=0;i<8;i++){await sleep(4000);const tx=await dump(d);console.log(`+${(i+1)*4}s: ${JSON.stringify(tx)}`);if(/Configure Wi-?Fi|Enter Wi-?Fi|SSID|Connecting to your router|found|Configure network/i.test(tx.join(' '))){console.log('==到配网/发现==');break;}}
}catch(e:any){console.error('FAIL:',e.message);}finally{await d.destroySession();}})();