138 lines
7.2 KiB
TypeScript
138 lines
7.2 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,
|
|
isDeviceOnHomepage,
|
|
enterPairingMode,
|
|
configureHubWifi,
|
|
} 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') });
|
|
|
|
// AI Art Frame:**流程同 AI Hub**(relay ch46,长按 3s 进添加模式)。入口品类「AI Art Frame」。
|
|
// 选品类 → 长按 ch46 3s → Connect Device → 同意隐私 → 等发现(上电约1分钟) → WiFi 配网。
|
|
// 入口名/首页名 env 可覆盖。ONES 添加号待补,先 [P0]。
|
|
const FRAME_NAME = process.env.AI_ART_FRAME_NAME || 'AI Art Frame';
|
|
const CATEGORY = process.env.AI_ART_FRAME_CATEGORY || 'AI Art Frame';
|
|
// 首页/校验关键字:首页设备名实测渲染为 "Al Art Frame C6"(AI→Al,小写L),用无歧义的 "Art Frame" 匹配(AI/Al 通吃且唯一)
|
|
const HOME_KW = process.env.AI_ART_FRAME_HOME || 'Art Frame';
|
|
const ADD_ANCHOR = '[P0]'; // TODO: 待补 AI Art Frame 添加 ONES 编号
|
|
|
|
describe('AIArtFrame Connect - 添加AI Art Frame设备', () => {
|
|
let driver: DeviceDriver;
|
|
let reporter: TestReporter;
|
|
|
|
beforeAll(async () => {
|
|
driver = createDriver();
|
|
await driver.createSession();
|
|
reporter = new TestReporter('AIArtFrame_Connect', driver.platform.toUpperCase());
|
|
});
|
|
|
|
afterAll(async () => {
|
|
reporter.generate();
|
|
await driver.destroySession();
|
|
});
|
|
|
|
it(`${ADD_ANCHOR} 通过BLE+WiFi添加AI Art Frame`, { timeout: 360000 }, async () => {
|
|
const start = Date.now();
|
|
const wifi = getWifiCredentials();
|
|
try {
|
|
const alreadyExists = await isDeviceOnHomepage(driver, HOME_KW);
|
|
if (alreadyExists) {
|
|
console.log(`${FRAME_NAME}已在首页,跳过重新添加`);
|
|
reporter.record(`${ADD_ANCHOR} 添加${FRAME_NAME}`, 'SKIP', Date.now() - start, `${FRAME_NAME}已存在`);
|
|
return;
|
|
}
|
|
|
|
const result = await addDeviceViaBLE(driver, {
|
|
categoryName: CATEGORY,
|
|
deviceKeyword: HOME_KW,
|
|
scanTimeout: 15000,
|
|
skipScanStep: true,
|
|
skipNextButton: true,
|
|
wizardButtons: ['Start now', 'Return Home', 'Done', 'Use now', 'Start Using', 'Got it', 'OK', 'Skip', 'Next', 'Save'],
|
|
connectionKeywords: [
|
|
'Initial Setup', 'Start Using', 'Done', 'added successfully', 'Added successfully',
|
|
'Got it', 'cloud service', 'Pick a room', 'Display Type', 'Select a room',
|
|
'Wi-Fi', 'WiFi', 'SSID', 'Network', 'Configure Wi-Fi', 'Connecting', 'Start now',
|
|
],
|
|
preSelectSteps: async (d: DeviceDriver) => {
|
|
// 选品类后可能有 Agree/免责页
|
|
const agreeEl = await d.findElementRaw('name', 'Agree').catch(() => null);
|
|
if (agreeEl) { await d.clickElement(agreeEl); await sleep(2000); }
|
|
|
|
// 继电器 ch46 长按 3s 进添加模式。AI_ART_FRAME_NO_RELAY=1:设备已手动进配对则跳过。
|
|
if (!process.env.AI_ART_FRAME_NO_RELAY) {
|
|
await enterPairingMode('ai_art_frame').catch((e) => console.log(`relay ch46 长按失败: ${e.message}`));
|
|
console.log('AI Art Frame: 已长按继电器 3s,等待设备启动...');
|
|
await sleep(5000);
|
|
} else {
|
|
console.log('AI Art Frame: 跳过继电器(设备已手动进配对)');
|
|
}
|
|
|
|
// 点 Connect Device 开始搜索
|
|
for (const t of ['Connect device', 'Connect Device', 'Connect devices', 'Connect Devices']) {
|
|
const b = await d.findElementRaw('-android uiautomator', `new UiSelector().text("${t}")`).catch(() => null);
|
|
if (b) { console.log(`AI Art Frame: 点击 "${t}" 开始搜索`); await d.clickElement(b); await sleep(2000); break; }
|
|
}
|
|
// 隐私协议(可能先勾选框再点 Agree)
|
|
await sleep(1500);
|
|
{
|
|
const cb = await d.findElementRaw('-android uiautomator', 'new UiSelector().className("android.widget.CheckBox")').catch(() => null);
|
|
if (cb) { await d.clickElement(cb).catch(() => {}); await sleep(500); }
|
|
for (const t of ['Agree', 'Agree and Continue', 'I Agree', 'Accept', 'Continue', '同意', '同意并继续']) {
|
|
const a = await d.findElementRaw('-android uiautomator', `new UiSelector().text("${t}")`).catch(() => null)
|
|
|| await d.findElementRaw('-android uiautomator', `new UiSelector().textContains("${t}")`).catch(() => null);
|
|
if (a) { console.log(`AI Art Frame: 同意隐私协议 "${t}"`); await d.clickElement(a); await sleep(2500); break; }
|
|
}
|
|
}
|
|
// 等发现设备(上电后约1分钟才出现,最长 ~100s)
|
|
console.log('AI Art Frame: 等待发现设备...');
|
|
for (let i = 0; i < 33; i++) {
|
|
await sleep(3000);
|
|
const s = await d.getSource().catch(() => '');
|
|
if (/Configure Wi-?Fi|Wi-?Fi Settings|SSID|Network name|Pick a room|Select a room|Setting up|Connecting to your router|Verifying|Name your|added successfully|Start now|Select Device/i.test(s)) {
|
|
console.log('AI Art Frame: 已进入配网/后续页'); break;
|
|
}
|
|
}
|
|
},
|
|
postConnectionSteps: async (d: DeviceDriver) => {
|
|
// 若有 Select Device 列表,先选中再 Next(兼容,无则直接配网)
|
|
const src = await d.getSource();
|
|
if (/Select Device/i.test(src)) {
|
|
const dev = await d.findElementRaw('-android uiautomator', `new UiSelector().textMatches("(?i).*Art Frame.*")`).catch(() => null);
|
|
if (dev) { await d.tapElement(dev); await sleep(1500); }
|
|
const n = await d.findElementRaw('-android uiautomator', 'new UiSelector().text("Next")').catch(() => null);
|
|
if (n) { await d.tapElement(n); await sleep(3500); }
|
|
}
|
|
await configureHubWifi(d, wifi);
|
|
// 配网后进功能页可能弹"固件升级"框遮挡首页校验 → 关掉(Later/Not Now/稍后/Skip 等)
|
|
await sleep(2000);
|
|
for (let i = 0; i < 2; i++) {
|
|
let dismissed = false;
|
|
for (const t of ['Later', 'Not Now', 'Not now', 'Update Later', 'Skip', 'Cancel', 'Maybe Later', '稍后', '以后再说', '暂不升级', '取消', '忽略']) {
|
|
const b = await d.findElementRaw('-android uiautomator', `new UiSelector().textContains("${t}")`).catch(() => null);
|
|
if (b) { await d.tapElement(b).catch(() => {}); console.log(`AI Art Frame: 关闭升级弹框 "${t}"`); await sleep(1500); dismissed = true; break; }
|
|
}
|
|
if (!dismissed) break;
|
|
}
|
|
},
|
|
});
|
|
expect(result).toBe(true);
|
|
|
|
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
|
reporter.record(`${ADD_ANCHOR} 添加${FRAME_NAME}`, 'PASS', Date.now() - start, `添加成功(WiFi:${wifi.ssid}), 耗时${elapsed}s`);
|
|
} catch (e: any) {
|
|
const ss = await driver.screenshot().catch(() => '');
|
|
reporter.record(`${ADD_ANCHOR} 添加${FRAME_NAME}`, 'FAIL', Date.now() - start, e.message, ss);
|
|
throw e;
|
|
}
|
|
});
|
|
});
|