AI_UIAutomation/scripts/dump-cats.ts

29 lines
1.1 KiB
TypeScript

import { createDriver } from '../drivers/factory';
import { navigateToAddPage } from '../utils/common/navigation.helper';
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
(async () => {
const d = createDriver();
await d.createSession();
await navigateToAddPage(d, 'Device');
await sleep(1500);
const found = new Set<string>();
for (let i = 0; i < 20; i++) {
// 展开 Show More(若有)
const more = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Show More")');
if (more) { await d.tapElement(more); await sleep(1500); }
const s = await d.getSource();
const m = s.match(/(?:text|content-desc)="([^"]+)"/g) || [];
m.forEach((x) => {
const v = x.replace(/^(?:text|content-desc)="/, '').replace(/"$/, '');
if (v && v.length < 45 && /Lamp|Floor|Strip|Light|Glow|Tube|LED|Lantern|Bulb|RGBIC|Neon|Wall/i.test(v)) found.add(v);
});
await d.scrollDown(500);
await sleep(700);
}
console.log('=== 灯类相关品类(展开后) ===');
console.log([...found].sort().join('\n'));
await d.destroySession();
})();