import { createDriver } from '../drivers/factory'; import { configureHubWifi } from '../utils/common/hub.helper'; import { getWifiCredentials } from '../config/wifi.config'; const sleep=(ms:number)=>new Promise(r=>setTimeout(r,ms)); const dump=async(d:any):Promise=>[...new Set((Array.from((await d.getSource()).matchAll(/text="([^"]+)"/g)) as any[]).map(m=>m[1]).filter((t:string)=>t.trim()&&t.length<30))].slice(0,20) as string[]; (async()=>{const d=createDriver();await d.createSession();try{ console.log('起始页: '+JSON.stringify(await dump(d))); const cn=await d.findElementRaw('-android uiautomator','new UiSelector().textContains("Configure network")').catch(()=>null); if(cn){await d.tapElement(cn);console.log('点了 Configure network');await sleep(3000);} await configureHubWifi(d, getWifiCredentials()); await sleep(3000); console.log('配网后: '+JSON.stringify(await dump(d))); // 回首页看真实卡名 await d.goBackToHomepage().catch(()=>{}); await sleep(2000); const home=await dump(d); console.log('首页含S1/Plus: '+JSON.stringify(home.filter(t=>/S1|Plus|Robot|Vacuum/i.test(t)))); }catch(e:any){console.error('FAIL:',e.message);}finally{await d.destroySession();}})();