44 lines
3.2 KiB
TypeScript
44 lines
3.2 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 { enterPairingMode } from '../utils/common/relay.helper';
|
|
import { sleep, waitForSource } from '../utils/common/element.helper';
|
|
|
|
// 走 curtain3 全程,到 Auto-Calibrate Close 后逐页 dump,看真实收尾流程
|
|
async function main() {
|
|
const d = createDriver();
|
|
await d.createSession();
|
|
try {
|
|
const dump = async (l: string) => { const s = await d.getSource(); const t = Array.from(s.matchAll(/text="([^"]{1,60})"/g)).map(m => m[1]).filter(Boolean); console.log(`\n=== ${l} ===\n`, Array.from(new Set(t)).join(' | ')); return s; };
|
|
const tapText = async (txt: string) => { const e = await d.findElementRaw('-android uiautomator', `new UiSelector().text("${txt}")`); if (e) { await d.tapElement(e); console.log(' 点', txt); return true; } return false; };
|
|
const tapDesc = async (desc: string) => { const e = await d.findElementRaw('-android uiautomator', `new UiSelector().descriptionContains("${desc}")`); if (e) { await d.tapElement(e); console.log(' 勾', desc); return true; } return false; };
|
|
|
|
await navigateToAddPage(d, 'Device'); await sleep(2500);
|
|
await selectDeviceCategory(d, 'Curtain');
|
|
let s = await d.getSource();
|
|
if (s.includes('Disclaimer')) { await tapText('Next'); await sleep(2500); }
|
|
await enterPairingMode('curtain3').catch(() => {});
|
|
await sleep(1500); await tapText('Next');
|
|
|
|
await waitForSource(d, 'Select Mode', 60000).catch(() => {});
|
|
if (!(await tapDesc('Open from one side'))) await tapText('Open from one side');
|
|
await sleep(1000); await tapText('Confirm');
|
|
await waitForSource(d, 'Install', 30000).catch(() => {});
|
|
await tapText('Install');
|
|
await waitForSource(d, 'rail type', 15000).catch(() => {}); await tapText('Skip');
|
|
await waitForSource(d, 'Custom Calibration', 15000).catch(() => {}); await tapText('Custom Calibration');
|
|
await waitForSource(d, 'Confirm Orientation', 15000).catch(() => {}); await tapDesc('facing inwards'); await sleep(800); await tapText('Next');
|
|
await waitForSource(d, 'fully closed', 15000).catch(() => {}); await tapDesc('fully closed'); await sleep(800); await tapText('Start Calibration');
|
|
await waitForSource(d, 'Magnet Detection', 15000).catch(() => {}); await tapText('Skip magnet detection'); await sleep(1500); await tapText('Skip');
|
|
await waitForSource(d, 'Move left', 20000).catch(() => {});
|
|
await tapText('Move left'); console.log('等15s...'); await sleep(15000);
|
|
await tapText('Auto-Calibrate Close');
|
|
// ↓↓↓ 重点:Auto-Calibrate Close 之后逐页观察
|
|
for (let i = 1; i <= 12; i++) { await sleep(3000); s = await dump(`Auto-Close 后 第${i}页`); const left = await d.findElementsRaw('id', 'com.theswitchbot.switchbot:id/leftCard'); if (left.length) { console.log(`>>> 回首页 卡片=${left.length}`); break; } }
|
|
} finally { await d.destroySession(); }
|
|
}
|
|
main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });
|