import * as dotenv from 'dotenv'; import * as path from 'path'; dotenv.config({ path: path.resolve(__dirname, '../.env') }); import { createDriver } from '../drivers/factory'; import { findHomeCard } from '../utils/common/device-settings.helper'; import { sleep } from '../utils/common/element.helper'; import * as fs from 'fs'; (async () => { const d = createDriver(); await d.createSession(); await d.goBackToHomepage(); await sleep(800); const el = await findHomeCard(d, 'Meter 0B'); if (el) { await d.tapElement(el); await sleep(4000); } // 等 BLE 连 const openGearSettings = async () => { await d.tap(996,146); await sleep(2500); }; const dump = async (tag:string) => { const s = await d.getSource(); const rows = [...s.matchAll(/(?:text|content-desc)="([^"]+)"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/g)].map(m=>({t:m[1],y:+m[3],x:+m[2]})).filter(r=>r.t.length>=1).sort((a,b)=>a.y-b.y); console.log(`\n== ${tag} ==`); for(const r of rows.slice(0,22)) console.log(` y=${String(r.y).padStart(4)} x=${r.x} "${r.t}"`); const png=await d.screenshot().catch(()=>''); if(png) fs.writeFileSync(`/tmp/meter_${tag}.png`, Buffer.from(png,'base64')); }; await openGearSettings(); // Alert Conditions:重试 3 次(BLE) for (let r=0;r<3;r++){ await d.tap(540,566); await sleep(3000); const s=await d.getSource(); if(!/Third-party Services/.test(s) && !/Loading error/.test(s)){ console.log(`Alert 第${r+1}次进入`); break; } console.log(`Alert 第${r+1}次未进(BLE?),重试`); if(/Loading error/.test(s)) await sleep(3000); } await dump('alert'); // 回设置页 → Calibration 重试 await d.goBack(); await sleep(2000); for (let r=0;r<3;r++){ await d.tap(540,736); await sleep(3000); const s=await d.getSource(); if(!/Loading error/.test(s) && /Calibrat|Temperature/.test(s)){ console.log(`Calib 第${r+1}次加载`); break; } console.log(`Calib 第${r+1}次 Loading error,重试`); await d.goBack().catch(()=>{}); await sleep(2500); } await dump('calib'); await d.destroySession(); })().catch(e=>{console.error('ERR',e.message);process.exit(1);});