94 lines
4.3 KiB
TypeScript
94 lines
4.3 KiB
TypeScript
import { describe, it, beforeAll, afterAll, expect } from 'vitest';
|
|
import { DeviceDriver } from '../../drivers/types';
|
|
import { createDriver } from '../../drivers/factory';
|
|
import { TestReporter } from '../../utils/test-reporter';
|
|
import {
|
|
sleep,
|
|
addDeviceViaBLE,
|
|
findDeviceNameOnHomepage,
|
|
saveAddedDevice,
|
|
enterPairingMode,
|
|
configureHubWifi,
|
|
setupResilientHooks,
|
|
} from '../../utils/common';
|
|
import { getWifiCredentials } from '../../config/wifi.config';
|
|
import * as dotenv from 'dotenv';
|
|
import * as path from 'path';
|
|
|
|
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
|
|
|
|
// 扫地机 K20+:WiFi 产品。流程同 S1 Plus(机器人配置向导):入口「robot vacuum K20+」→ 第一步 Next →
|
|
// 第二步按 ch13+14 5s → Search 发现 found → 点 Configure network → WiFi 配网(Next 后弹"要连接至设备吗"点连接)。
|
|
const CATEGORY = process.env.ROBOT_K20P_CATEGORY || 'robot vacuum K20+';
|
|
const MODEL = process.env.ROBOT_K20P_MODEL || 'K20+';
|
|
const SCAN_KEYWORD = process.env.ROBOT_K20P_SCAN || 'K20';
|
|
const NAME_PATTERN = process.env.ROBOT_K20P_PATTERN || 'K20\\+?[^"]*\\s*[0-9A-Za-z]{0,4}';
|
|
const ADD_ANCHOR = '[P0]'; // TODO: 待补 扫地机 K20+ 添加 ONES 编号
|
|
|
|
describe('Robot K20+ Connect - 添加扫地机K20+(第二步两键同按 + WiFi配网)', () => {
|
|
let driver: DeviceDriver;
|
|
let reporter: TestReporter;
|
|
setupResilientHooks(() => driver);
|
|
|
|
beforeAll(async () => {
|
|
driver = createDriver();
|
|
await driver.createSession();
|
|
reporter = new TestReporter('RobotK20P_Connect', driver.platform.toUpperCase());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
reporter.generate();
|
|
await driver.destroySession();
|
|
});
|
|
|
|
it(`${ADD_ANCHOR} 通过BLE+WiFi添加扫地机K20+`, { timeout: 300000 }, async () => {
|
|
const start = Date.now();
|
|
const wifi = getWifiCredentials();
|
|
try {
|
|
const existing = await findDeviceNameOnHomepage(driver, NAME_PATTERN);
|
|
if (existing) {
|
|
console.log(`${existing}已在首页,跳过重新添加`);
|
|
saveAddedDevice('robot', existing);
|
|
reporter.record(`${ADD_ANCHOR} 添加扫地机K20+`, 'SKIP', Date.now() - start, `${existing}已存在`);
|
|
return;
|
|
}
|
|
|
|
const result = await addDeviceViaBLE(driver, {
|
|
categoryName: CATEGORY,
|
|
deviceKeyword: SCAN_KEYWORD,
|
|
scanTimeout: 30000,
|
|
skipScanStep: true,
|
|
// 流程同空净:① 过 Disclaimers/Next(若有)② 长按 ch13+14 5s 进入添加模式 → 点 Connect Device/Next
|
|
preSelectSteps: async (d) => {
|
|
for (let i = 0; i < 2; i++) {
|
|
const n = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")').catch(() => null);
|
|
if (!n) break;
|
|
await d.tapElement(n); await sleep(2000);
|
|
}
|
|
await enterPairingMode('robot_k20p').catch((e) => console.log(`relay ch13+14 配对失败: ${e.message}`));
|
|
await sleep(2500);
|
|
const btn = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Connect Device")').catch(() => null)
|
|
|| await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Connect device")').catch(() => null)
|
|
|| await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")').catch(() => null);
|
|
if (btn) { await d.tapElement(btn); await sleep(3000); }
|
|
},
|
|
// 配网(configureHubWifi 已处理"要连接至设备吗"点连接弹框)
|
|
postConnectionSteps: async (d) => { await configureHubWifi(d, wifi); },
|
|
wizardButtons: ['Start now', 'Return Home', 'Done', 'Use now', 'Start Using', 'Got it', 'OK', 'Skip', 'Next', 'Save'],
|
|
connectionKeywords: [
|
|
'Configure Wi-Fi', 'Wi-Fi Settings', 'Connecting', 'Pick a room', 'Done',
|
|
'added successfully', 'Added successfully', 'Initial Setup', 'Start now', 'Select a room', 'Enter Wi-Fi',
|
|
],
|
|
});
|
|
expect(result).toBe(true);
|
|
|
|
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
|
reporter.record(`${ADD_ANCHOR} 添加扫地机K20+`, 'PASS', Date.now() - start, `添加成功(WiFi:${wifi.ssid}), 耗时${elapsed}s`);
|
|
} catch (e: any) {
|
|
const ss = await driver.screenshot().catch(() => '');
|
|
reporter.record(`${ADD_ANCHOR} 添加扫地机K20+`, 'FAIL', Date.now() - start, e.message, ss);
|
|
throw e;
|
|
}
|
|
});
|
|
});
|