|
| 1 | +import { spawn, type ChildProcess } from 'node:child_process'; |
| 2 | +import { resolve } from 'node:path'; |
| 3 | +import { afterAll, beforeAll, describe, it, vi } from 'vitest'; |
| 4 | +import { |
| 5 | + type ComputerAgent, |
| 6 | + agentFromComputer, |
| 7 | +} from '@midscene/computer'; |
| 8 | + |
| 9 | +vi.setConfig({ testTimeout: 8 * 60 * 1000, hookTimeout: 2 * 60 * 1000 }); |
| 10 | + |
| 11 | +const sleep = (milliseconds: number) => |
| 12 | + new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds)); |
| 13 | + |
| 14 | +const stopProcessGroup = (child?: ChildProcess) => { |
| 15 | + if (!child?.pid) return; |
| 16 | + try { |
| 17 | + process.kill(-child.pid, 'SIGTERM'); |
| 18 | + } catch { |
| 19 | + // The fixture may already have exited after a test failure. |
| 20 | + } |
| 21 | +}; |
| 22 | + |
| 23 | +describe('Doubao Say onboarding', () => { |
| 24 | + let agent: ComputerAgent; |
| 25 | + let fluxbox: ChildProcess; |
| 26 | + let fixture: ChildProcess; |
| 27 | + |
| 28 | + beforeAll(async () => { |
| 29 | + agent = await agentFromComputer({ |
| 30 | + aiActionContext: |
| 31 | + 'You are testing the English Doubao Say GTK onboarding window. ' + |
| 32 | + 'Interact only with the Doubao Say window and use visible labels.', |
| 33 | + xvfbResolution: '1280x960x24', |
| 34 | + }); |
| 35 | + |
| 36 | + fluxbox = spawn('fluxbox', [], { |
| 37 | + detached: true, |
| 38 | + stdio: 'ignore', |
| 39 | + env: process.env, |
| 40 | + }); |
| 41 | + await sleep(1000); |
| 42 | + |
| 43 | + const repositoryRoot = resolve(import.meta.dirname, '../../..'); |
| 44 | + fixture = spawn('/usr/bin/python3', ['tests/midscene/gtk_fixture.py'], { |
| 45 | + cwd: repositoryRoot, |
| 46 | + detached: true, |
| 47 | + stdio: ['ignore', 'inherit', 'inherit'], |
| 48 | + env: { |
| 49 | + ...process.env, |
| 50 | + GTK_A11Y: 'none', |
| 51 | + PYTHONPATH: resolve(repositoryRoot, 'src'), |
| 52 | + XDG_CONFIG_HOME: resolve(repositoryRoot, '.midscene-config'), |
| 53 | + }, |
| 54 | + }); |
| 55 | + await sleep(2500); |
| 56 | + }); |
| 57 | + |
| 58 | + afterAll(() => { |
| 59 | + stopProcessGroup(fixture); |
| 60 | + stopProcessGroup(fluxbox); |
| 61 | + }); |
| 62 | + |
| 63 | + it('navigates, reports endpoint feedback, resets scroll and completes setup', async () => { |
| 64 | + await agent.aiAct( |
| 65 | + 'Verify the visible Doubao Say window is on the Microphone step and has a Next button in the fixed top navigation.', |
| 66 | + ); |
| 67 | + |
| 68 | + await agent.aiAct( |
| 69 | + 'Click the Next button in the fixed top navigation and wait until the current step is Trigger key.', |
| 70 | + ); |
| 71 | + await agent.aiAct( |
| 72 | + 'In the Voice polishing section, scroll within the window if needed, click Test endpoint, and wait for the endpoint result.', |
| 73 | + ); |
| 74 | + await agent.aiAct( |
| 75 | + 'Verify a visible message says the endpoint works and includes Synthetic endpoint response.', |
| 76 | + ); |
| 77 | + |
| 78 | + await agent.aiAct( |
| 79 | + 'Click the Next button in the fixed top navigation and wait for the Voice test step.', |
| 80 | + ); |
| 81 | + await agent.aiAct( |
| 82 | + 'Verify the Voice test heading and its introductory text are visible near the top of the content, showing that the page did not remain scrolled to the bottom.', |
| 83 | + ); |
| 84 | + await agent.aiAct( |
| 85 | + 'Scroll within the content if needed and click the Finish setup button.', |
| 86 | + ); |
| 87 | + await agent.aiAct( |
| 88 | + 'Verify the visible feedback says Setup completed by the synthetic E2E fixture.', |
| 89 | + ); |
| 90 | + }); |
| 91 | +}); |
0 commit comments