AI_UIAutomation/scripts/debug-bot-scan.ts

35 lines
1.6 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 { navigateToAddPage } from '../utils/common/navigation.helper';
import { selectDeviceCategory } from '../utils/common/device-add.helper';
import { sleep } from '../utils/common/element.helper';
// 进 Bot 添加扫描页,dump 扫描列表里多个 Bot 的真实条目(看是否带唯一后缀/MAC)
async function main() {
const category = process.argv[2] || 'Bot';
const driver = createDriver();
await driver.createSession();
try {
await navigateToAddPage(driver, 'Device');
await sleep(2500);
const ok = await selectDeviceCategory(driver, category);
console.log(`选品类 ${category}:`, ok);
// 扫描页多次采样,dump 所有含 Bot 的条目(text + content-desc)
for (let i = 1; i <= 4; i++) {
await sleep(2500);
const src = await driver.getSource();
const t = Array.from(src.matchAll(/text="([^"]{1,40})"/g)).map((m) => m[1]).filter(Boolean);
const d = Array.from(src.matchAll(/content-desc="([^"]{1,40})"/g)).map((m) => m[1]).filter(Boolean);
const all = Array.from(new Set([...t, ...d]));
const bots = all.filter((x) => /bot|[0-9A-Fa-f]{2}$|:|MAC/i.test(x));
console.log(`\n采样#${i} 全部:`, all.join(' | '));
console.log(`采样#${i} 疑似设备/ID:`, bots.join(' | '));
}
} finally {
await driver.destroySession();
}
}
main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });