AI_UIAutomation/scripts/explore-curtain-card.ts

21 lines
1.1 KiB
TypeScript

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';
(async () => {
const d = createDriver(); await d.createSession();
await d.goBackToHomepage(); await sleep(1000);
const name = process.env.CT || 'Curtain3 Auto';
await findHomeCard(d, name);
const src = await d.getSource();
// 找该卡的 content-desc 或 text 出现位置,打印前后窗口
let idx = src.indexOf(`text="${name}"`);
if (idx < 0) idx = src.indexOf(`content-desc="${name}`);
if (idx < 0) idx = src.indexOf(name);
console.log(`name idx=${idx}`);
const win = src.slice(Math.max(0, idx - 400), idx + 900).replace(/></g, '>\n<');
console.log(win.split('\n').filter(l => /text="[^"]+"|content-desc="[^"]+"/.test(l)).slice(0, 25).join('\n'));
await d.destroySession();
})().catch(e => { console.error('ERR', e.message); process.exit(1); });