verify-mobile-wait-probe.mjs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env node
  2. /* 移动端等待提示验证(修正版):点发送按钮(手机回车=换行,Enter 不发送) */
  3. import { chromium, devices } from 'playwright';
  4. import { resolve, dirname } from 'node:path';
  5. import { fileURLToPath } from 'node:url';
  6. const outDir = resolve(dirname(fileURLToPath(import.meta.url)), '../test-results/ui-experience-20261202');
  7. const BASE = process.env.BASE_URL || 'http://127.0.0.1:4300';
  8. const browser = await chromium.launch({ channel: 'chrome' });
  9. const ctx = await browser.newContext({ ...devices['Pixel 7'], viewport: { width: 390, height: 844 } });
  10. const page = await ctx.newPage();
  11. page.on('pageerror', (e) => console.log('PAGEERR', String(e)));
  12. await page.goto(`${BASE}/mobile/messages`, { waitUntil: 'domcontentloaded' });
  13. await page.waitForTimeout(9000);
  14. await page.locator('text=技能锁定测试').first().click();
  15. await page.waitForTimeout(5000);
  16. const box = page.locator('textarea').first();
  17. await box.click();
  18. await box.fill('请用 terminal 依次执行 echo m-step-1、sleep 15、echo m-step-2,每步之间报告进度。');
  19. await page.locator('.m-send').click();
  20. console.log('已点击发送按钮');
  21. let sawWait = false;
  22. let sawRunning = false;
  23. let sawLive = false;
  24. for (let i = 0; i < 20; i++) {
  25. const probe = await page.evaluate(() => {
  26. const turns = [...document.querySelectorAll('app-assistant-turn')];
  27. const last = turns[turns.length - 1];
  28. const txt = (sel) => [...document.querySelectorAll(sel)].map((e) => e.textContent.replace(/\s+/g, ' ').trim());
  29. return {
  30. turnCount: turns.length,
  31. lastTurn: last ? (last.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 120) : null,
  32. wait: txt('.card-wait'),
  33. running: txt('.card-running'),
  34. liveSteps: document.querySelectorAll('app-live-activity .step, app-live-activity li, app-live-activity .live-step').length,
  35. liveVisible: !!document.querySelector('app-live-activity'),
  36. };
  37. });
  38. console.log(`[+${i * 2}s]`, JSON.stringify(probe));
  39. if (probe.wait.length) sawWait = true;
  40. if (probe.running.length) sawRunning = true;
  41. if (probe.liveVisible && probe.liveSteps > 0) sawLive = true;
  42. if (i === 3) await page.screenshot({ path: resolve(outDir, 'm-04-wait.png') });
  43. if (i === 8) await page.screenshot({ path: resolve(outDir, 'm-05-live.png') });
  44. await page.waitForTimeout(2000);
  45. }
  46. console.log('=== 结论 ===');
  47. console.log('④ 等待期文字提示(已送达·正在思考 / 已处理 Ns):', sawWait || sawRunning ? 'OK' : 'FAIL');
  48. console.log('⑤ 过程中实时步骤区:', sawLive ? 'OK' : '(未出现,可能任务太快或进度消息未达)');
  49. await browser.close();