AI_UIAutomation/scripts/probe-pair.ts

21 lines
2.0 KiB
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<30))] as string[];
(async()=>{const d=createDriver();await d.createSession();try{
// 进 keypad 功能页
await d.dismissPopupIfPresent();await d.goBackToHomepage();await sleep(1000);
let el=null;for(let i=0;i<8;i++){el=await d.findElementRaw('-android uiautomator','new UiSelector().textContains("Keypad Vision")').catch(()=>null);if(el)break;await d.swipe(540,1500,540,700,0.4).catch(()=>{});await sleep(700);}
const r=await d.getElementRect(el!);await d.tap(r.x+100,r.y-20);await sleep(5000);await d.dismissPopupIfPresent();await sleep(1500);
const cb=await d.findElementRaw('-android uiautomator','new UiSelector().textContains("Do not show again")').catch(()=>null);
if(cb){await d.tapElement(cb).catch(()=>{});for(const t of['OK','Got it','Confirm']){const b=await d.findElementRaw('-android uiautomator',`new UiSelector().text("${t}")`).catch(()=>null);if(b){await d.tapElement(b);await sleep(1500);break;}}}
const pair=await d.findElementRaw('-android uiautomator','new UiSelector().textContains("Pair to Lock")').catch(()=>null);
if(pair){await d.tapElement(pair);await sleep(3000);}
console.log('选锁页: '+JSON.stringify(await dump(d)));
// 点 Lock 6D 行
const lk=await d.findElementRaw('-android uiautomator','new UiSelector().textContains("Lock 6D")').catch(()=>null);
if(lk){await d.tapElement(lk);await sleep(2500);console.log('点Lock 6D后: '+JSON.stringify(await dump(d)));}
// 再点 Pair
const pb=await d.findElementRaw('-android uiautomator','new UiSelector().text("Pair")').catch(()=>null);
if(pb){await d.tapElement(pb);await sleep(6000);console.log('点Pair后: '+JSON.stringify(await dump(d)));}
}catch(e:any){console.error('FAIL:',e.message);}finally{await d.destroySession();}})();