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') }); // Strip Light(灯带):灯类 WiFi 产品(relay ch33)。流程同 Color Bulb/吸顶灯:**点一次→等2s→再点一次** 进配对 + WiFi 配网 + Start now 完成。 const CATEGORY = process.env.STRIP_LIGHT_CATEGORY || 'Strip Light'; // 'Strip Light' 会被 "RGBWW/RGBICWW Strip Light 3" 等变体串台(误 SKIP/误判)→ 照 curtain/plug:加时改名为唯一名,skip/校验用改名后的名。 const RENAME_TO = process.env.STRIP_LIGHT_RENAME || 'Strip Light SB'; const SCAN_KEYWORD = process.env.STRIP_LIGHT_SCAN || RENAME_TO; // skipScanStep=true → 仅首页校验 const NAME_PATTERN = process.env.STRIP_LIGHT_PATTERN || RENAME_TO; describe('StripLight Connect - 添加灯带(两次点按配对 + WiFi配网)', () => { let driver: DeviceDriver; let reporter: TestReporter; setupResilientHooks(() => driver); beforeAll(async () => { driver = createDriver(); await driver.createSession(); reporter = new TestReporter('StripLight_Connect', driver.platform.toUpperCase()); }); afterAll(async () => { reporter.generate(); await driver.destroySession(); }); it('[P0][ONES:15959] 通过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('stripLight', existing); reporter.record('[P0][ONES:15959] 添加灯带', 'SKIP', Date.now() - start, `${existing}已存在`); return; } const result = await addDeviceViaBLE(driver, { categoryName: CATEGORY, deviceKeyword: SCAN_KEYWORD, registryCategory: 'stripLight', // 独立 key,灯控制按注册名找卡片(方案A) namePattern: NAME_PATTERN, scanTimeout: 30000, skipScanStep: true, // 对齐其它灯:配对后直连(无扫描列表),否则卡 "not found in BLE scan";WiFi 输入由 configureHubWifi 的 settle-wait 统一处理 // 选品类后:① 过 Disclaimers(若有)② 进配对:长按配对键 2s(relay ch33;灯带是长按,非两次点按) 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('strip_light').catch((e) => console.log(`relay ch33 长按配对失败: ${e.message}`)); await sleep(2000); const btn = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Connect Device")'); if (btn) { await d.tapElement(btn); await sleep(3000); } }, postConnectionSteps: async (d) => { await configureHubWifi(d, wifi, { renameTo: RENAME_TO }); }, // 命名页完成按钮 "Start now"(默认向导没有,灯类必须加,否则设备不落账号) 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('strip_light', 'main', 400).catch((e) => console.log(`关灯按键失败: ${e.message}`)); await sleep(1000); const elapsed = ((Date.now() - start) / 1000).toFixed(1); reporter.record('[P0][ONES:15959] 添加灯带', 'PASS', Date.now() - start, `添加成功(WiFi:${wifi.ssid}), 耗时${elapsed}s`); } catch (e: any) { const ss = await driver.screenshot().catch(() => ''); reporter.record('[P0][ONES:15959] 添加灯带', 'FAIL', Date.now() - start, e.message, ss); throw e; } }); });