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 { sleep } from '../utils/common/element.helper'; // 抓取 App「添加设备」完整产品目录(产品看板),输出全部单品设备名 async function main() { const driver = createDriver(); await driver.createSession(); try { await navigateToAddPage(driver, 'Device'); await sleep(2500); // 点 Show More 展开全部品类 const more = await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Show More")'); if (more) { await driver.tapElement(more); await sleep(1500); } const all = new Set(); // 非产品的 UI 文案/区块标题,过滤掉 const NON_PRODUCT = new Set([ 'Add Device', 'Scanning for Bluetooth devices nearby...', 'Show More', 'Show less', 'Add Manually', 'Home Automation', 'Smart Home Appliances', 'Sensor', 'Camera', 'Lock', 'Light', 'Curtain', 'Hub', 'Robot Vacuum', 'Others', 'Smart Switch', 'Climate', 'Security', 'Lighting', 'Cleaning', ]); for (let i = 0; i < 16; i++) { const src = await driver.getSource(); for (const m of src.matchAll(/text="([^"]{2,45})"/g)) { const t = m[1].trim(); if (!t) continue; if (/^\d+$/.test(t)) continue; // 纯数字(角标计数) if (NON_PRODUCT.has(t)) continue; all.add(t); } await driver.scrollDown(650); await sleep(900); } const list = Array.from(all).sort(); console.log('=== 产品目录(共 ' + list.length + ' 项,已过滤UI/区块标题)==='); list.forEach((x, i) => console.log(`${String(i + 1).padStart(3)}. ${x}`)); } finally { await driver.destroySession(); } } main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });