verify-device-busy-ring.mjs 2.3 KB

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