import { createDriver } from '../drivers/factory'; import * as fs from 'fs'; (async () => { const d = createDriver(); await d.createSession(); const KW='Color Bulb 7E', W=1080,H=2400; const sleep=(m:number)=>new Promise(r=>setTimeout(r,m)); try { await d.dismissPopupIfPresent(); await d.goBackToHomepage(); await sleep(800); let el=null; for(let i=0;i<10;i++){el=await d.findElementRaw('-android uiautomator',`new UiSelector().textContains("${KW}")`).catch(()=>null); if(el)break; await d.swipe(540,1500,540,700,0.4).catch(()=>{}); await sleep(800);} const r=await d.getElementRect(el!); await d.tap(r.x+r.width/2,r.y+r.height/2); await sleep(2500); const src=await d.getSource(); const pw=Array.from(src.matchAll(/clickable="true"[^>]*?bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/g)).map(m=>{const x1=+m[1],y1=+m[2],x2=+m[3],y2=+m[4];return{w:x2-x1,h:y2-y1,cx:(x1+x2)/2,cy:(y1+y2)/2};}).filter(b=>b.w>=150&&b.w<=320&&b.h>=150&&b.h<=320&&Math.abs(b.cx-W/2)H*0.4); const st=()=>d.getSource().then(s=>{const t=Array.from(s.matchAll(/text="([^"]+)"/g)).map(m=>m[1]);const i=t.findIndex(x=>x.includes(KW));return i>=0?t[i+1]||'':'';}); if(!/\d+\s*%/.test(await st()) && pw.length){await d.tap(Math.round(pw[0].cx),Math.round(pw[0].cy)); await sleep(3500);} const texts=[...new Set(Array.from((await d.getSource()).matchAll(/text="([^"]+)"/g)).map(m=>m[1]).filter(t=>t.trim()))]; console.log('TEXTS='+JSON.stringify(texts)); const ss=await d.screenshot(); fs.writeFileSync('/tmp/cb_popup.png',Buffer.from(ss,'base64')); console.log('OK'); } catch(e:any){console.error(e.message);} finally{await d.destroySession();} })();