77 lines
4.0 KiB
TypeScript
77 lines
4.0 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 } from '../utils/common/element.helper';
|
|
|
|
// 走 curtain 添加,过引导按继电器配对,然后逐页 dump,定位"行程校验"页及其交互
|
|
async function main() {
|
|
const category = process.argv[2] || 'Curtain';
|
|
const relayDevice = process.argv[3] || 'curtain';
|
|
const driver = createDriver();
|
|
await driver.createSession();
|
|
try {
|
|
const dump = async (label: string) => {
|
|
const src = await driver.getSource();
|
|
const t = Array.from(src.matchAll(/text="([^"]{1,50})"/g)).map((m) => m[1]).filter(Boolean);
|
|
const d = Array.from(src.matchAll(/content-desc="([^"]{1,50})"/g)).map((m) => m[1]).filter(Boolean);
|
|
console.log(`\n=== ${label} ===\n text:`, Array.from(new Set(t)).join(' | '), '\n desc:', Array.from(new Set(d)).join(' | '));
|
|
return src;
|
|
};
|
|
|
|
await navigateToAddPage(driver, 'Device');
|
|
await sleep(2500);
|
|
const ok = await selectDeviceCategory(driver, category);
|
|
console.log(`选品类 ${category}:`, ok);
|
|
if (!ok) return;
|
|
|
|
// 过 Disclaimers
|
|
let src = await dump('选品类后');
|
|
if (src.includes('Disclaimer')) {
|
|
const next = await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")');
|
|
if (next) { await driver.tapElement(next); await sleep(2500); }
|
|
}
|
|
await dump('引导页(按键前)');
|
|
|
|
// 继电器按开关键 2s 进配对
|
|
console.log(`\n>>> 继电器配对 ${relayDevice}...`);
|
|
await enterPairingMode(relayDevice).catch((e) => console.log('relay 失败:', e.message));
|
|
await sleep(2000);
|
|
// 点 Next 连接
|
|
const n = await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")');
|
|
if (n) { await driver.tapElement(n); console.log('点了 Next 连接'); }
|
|
|
|
// 逐页观察(含连接、选模式、行程校验、命名…),关键字命中即重点标注
|
|
for (let i = 1; i <= 20; i++) {
|
|
await sleep(3000);
|
|
src = await dump(`连接后 第${i}页`);
|
|
if (/Calibrat|行程|Stroke|stroke|校准|校正|Set.*Position|Travel|Adjust/i.test(src)) {
|
|
console.log(`\n>>> 第${i}页 疑似【行程校验】,停下详查`);
|
|
break;
|
|
}
|
|
// 选模式页:选"单边开合"再 Confirm
|
|
if (src.includes('Select Mode') || src.includes('Open from one side')) {
|
|
const one = await driver.findElementRaw('-android uiautomator', 'new UiSelector().textContains("Open from one side")')
|
|
|| await driver.findElementRaw('-android uiautomator', 'new UiSelector().descriptionContains("Open from one side")');
|
|
if (one) { await driver.tapElement(one); await sleep(1000); console.log(' → 选 Open from one side'); }
|
|
const conf = await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Confirm")');
|
|
if (conf) { await driver.tapElement(conf); console.log(' → Confirm'); }
|
|
continue;
|
|
}
|
|
const nx = await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")')
|
|
|| await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Got it")')
|
|
|| await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Start")')
|
|
|| await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Continue")')
|
|
|| await driver.findElementRaw('-android uiautomator', 'new UiSelector().text("Confirm")');
|
|
if (nx) { await driver.tapElement(nx); console.log(' → 点击推进'); }
|
|
else console.log(' (无按钮,等待…可能在连接中)');
|
|
}
|
|
} finally {
|
|
await driver.destroySession();
|
|
}
|
|
}
|
|
main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });
|