#!/usr/bin/env node /* 真机补验⑥:长任务运行中返回列表,捕捉忙碌环 */ import { spawnSync } from 'node:child_process'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { connectWebView } from './android-webview-cdp.mjs'; const here = dirname(fileURLToPath(import.meta.url)); const outDir = resolve(here, '../test-results/ui-experience-20261202'); const ADB = 'E:/coding-environment/AndroidSDK/platform-tools/adb.exe'; const SERIAL = '3e529a34'; const PORT = 9444; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const adb = (...args) => (spawnSync(ADB, ['-s', SERIAL, ...args], { encoding: 'utf8', timeout: 30000, windowsHide: true }).stdout || '').trim(); const pid = adb('shell', 'pidof', 'cn.fmode.app').split(/\s+/)[0]; adb('forward', '--remove', `tcp:${PORT}`); adb('forward', `tcp:${PORT}`, `localabstract:webview_devtools_remote_${pid}`); const page = await connectWebView(PORT); console.log('URL =', await page.evaluate(() => location.href)); /* 进会话发长任务 */ await page.evaluate(() => { const row = [...document.querySelectorAll('button, a, li')].find((e) => (e.textContent || '').includes('技能锁定测试')); (row.closest('button') || row.querySelector('button') || row).click(); }); await sleep(4000); await page.fill('textarea', '请用 terminal 执行 sleep 60 && echo busy-ring-device,然后报告。'); await page.evaluate(() => document.querySelector('.m-send').click()); await sleep(3000); console.log('已发长任务,回合状态 =', await page.evaluate(() => { const turns = [...document.querySelectorAll('app-assistant-turn')]; const last = turns[turns.length - 1]; return last ? (last.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 60) : null; })); /* 立刻回列表 */ await page.evaluate(() => { location.href = 'https://localhost/mobile/messages'; }); await sleep(4000); const probe = await page.evaluate(() => { const busy = [...document.querySelectorAll('.m-presence--busy')]; return { busyCount: busy.length, aria: busy.map((e) => e.getAttribute('aria-label')) }; }); console.log('列表忙碌环:', JSON.stringify(probe)); await page.screenshot(resolve(outDir, 'r-06-busy.png')); console.log(probe.busyCount > 0 ? '⑥ 真机列表忙碌环: OK' : '⑥ 真机列表忙碌环: FAIL'); page.close();