93 lines
4.0 KiB
TypeScript
93 lines
4.0 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,
|
|
pressButton,
|
|
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') });
|
|
|
|
// 落地灯(Floor Lamp):灯类 WiFi 产品(relay ch42)。流程同灯带/霓虹灯:长按配对键 2s + Connect Device 直连 + WiFi 配网 + Start now。
|
|
const CATEGORY = process.env.FLOOR_LAMP_CATEGORY || 'Floor Lamp';
|
|
const SCAN_KEYWORD = process.env.FLOOR_LAMP_SCAN || 'Floor Lamp';
|
|
const NAME_PATTERN = process.env.FLOOR_LAMP_PATTERN || 'Floor Lamp[^"]*\\s*[0-9A-Za-z]{0,4}';
|
|
|
|
describe('Floor Lamp Connect - 添加落地灯(长按配对 + WiFi配网)', () => {
|
|
let driver: DeviceDriver;
|
|
let reporter: TestReporter;
|
|
setupResilientHooks(() => driver);
|
|
|
|
beforeAll(async () => {
|
|
driver = createDriver();
|
|
await driver.createSession();
|
|
reporter = new TestReporter('FloorLamp_Connect', driver.platform.toUpperCase());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
reporter.generate();
|
|
await driver.destroySession();
|
|
});
|
|
|
|
it('[P0][ONES:301586] 通过BLE+WiFi添加落地灯', { timeout: 240000 }, async () => {
|
|
const start = Date.now();
|
|
const wifi = getWifiCredentials();
|
|
try {
|
|
const existing = await findDeviceNameOnHomepage(driver, NAME_PATTERN);
|
|
if (existing) {
|
|
console.log(`${existing}已在首页,跳过重新添加`);
|
|
saveAddedDevice('ceilingLight', existing);
|
|
reporter.record('[P0][ONES:301586] 添加落地灯', 'SKIP', Date.now() - start, `${existing}已存在`);
|
|
return;
|
|
}
|
|
|
|
const result = await addDeviceViaBLE(driver, {
|
|
categoryName: CATEGORY,
|
|
deviceKeyword: SCAN_KEYWORD,
|
|
scanTimeout: 30000,
|
|
skipScanStep: true, // Connect Device 直连进配网页,无扫描列表
|
|
// 选品类后:① 过 Disclaimers(若有)② 长按配对键 2s(relay ch42)→ 点 Next/Connect Device
|
|
preSelectSteps: async (d) => {
|
|
for (let i = 0; i < 2; i++) {
|
|
const n = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")');
|
|
if (!n) break;
|
|
await d.tapElement(n); await sleep(2000);
|
|
}
|
|
await enterPairingMode('floor_lamp').catch((e) => console.log(`relay ch42 长按配对失败: ${e.message}`));
|
|
await sleep(2000);
|
|
const btn = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Connect Device")')
|
|
|| await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")');
|
|
if (btn) { await d.tapElement(btn); await sleep(3000); }
|
|
},
|
|
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',
|
|
],
|
|
});
|
|
expect(result).toBe(true);
|
|
|
|
await pressButton('floor_lamp', 'main', 400).catch((e) => console.log(`关灯按键失败: ${e.message}`)); // 添加后关灯
|
|
await sleep(1000);
|
|
|
|
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
|
reporter.record('[P0][ONES:301586] 添加落地灯', 'PASS', Date.now() - start, `添加成功(WiFi:${wifi.ssid}), 耗时${elapsed}s`);
|
|
} catch (e: any) {
|
|
const ss = await driver.screenshot().catch(() => '');
|
|
reporter.record('[P0][ONES:301586] 添加落地灯', 'FAIL', Date.now() - start, e.message, ss);
|
|
throw e;
|
|
}
|
|
});
|
|
});
|