|
1 | 1 | import { existsSync } from 'node:fs'; |
2 | 2 | import { join } from 'node:path'; |
3 | 3 | import { PlaywrightAgent } from '@/playwright'; |
4 | | -import { sleep } from '@midscene/core/utils'; |
5 | 4 | import { getMidsceneRunSubDir } from '@midscene/shared/common'; |
6 | 5 | import { expect, test } from '@playwright/test'; |
7 | 6 |
|
8 | 7 | const REPLAY_ALL_SELECTOR = '.replay-all-mode-wrapper'; |
9 | 8 | const TIME_DISPLAY_SELECTOR = `${REPLAY_ALL_SELECTOR} .time-display`; |
10 | | -const PLAYBACK_ADVANCE_TIMEOUT = 30_000; |
11 | | -const PLAYBACK_COMPLETE_TIMEOUT = 90_000; |
12 | | -const PLAYBACK_POLL_INTERVAL = 500; |
13 | 9 | const TEST_TIMEOUT = 15 * 60 * 1000; |
14 | 10 |
|
15 | 11 | function parseTimeText(text: string): number { |
@@ -40,45 +36,6 @@ function getReportPath(reportFileName: string): string { |
40 | 36 | return join(getMidsceneRunSubDir('report'), `${reportFileName}.html`); |
41 | 37 | } |
42 | 38 |
|
43 | | -async function waitForPlaybackToAdvance( |
44 | | - readCurrentSeconds: () => Promise<number>, |
45 | | - previousSeconds: number, |
46 | | -): Promise<number> { |
47 | | - const startTime = Date.now(); |
48 | | - |
49 | | - while (Date.now() - startTime < PLAYBACK_ADVANCE_TIMEOUT) { |
50 | | - const currentSeconds = await readCurrentSeconds(); |
51 | | - if (currentSeconds > previousSeconds) { |
52 | | - return currentSeconds; |
53 | | - } |
54 | | - await sleep(PLAYBACK_POLL_INTERVAL); |
55 | | - } |
56 | | - |
57 | | - throw new Error( |
58 | | - `Replay time did not advance within ${PLAYBACK_ADVANCE_TIMEOUT}ms`, |
59 | | - ); |
60 | | -} |
61 | | - |
62 | | -async function waitForPlaybackToReach( |
63 | | - readCurrentSeconds: () => Promise<number>, |
64 | | - targetSeconds: number, |
65 | | - timeoutMs: number, |
66 | | -): Promise<number> { |
67 | | - const startTime = Date.now(); |
68 | | - |
69 | | - while (Date.now() - startTime < timeoutMs) { |
70 | | - const currentSeconds = await readCurrentSeconds(); |
71 | | - if (currentSeconds >= targetSeconds) { |
72 | | - return currentSeconds; |
73 | | - } |
74 | | - await sleep(PLAYBACK_POLL_INTERVAL); |
75 | | - } |
76 | | - |
77 | | - throw new Error( |
78 | | - `Replay time did not reach ${targetSeconds}s within ${timeoutMs}ms`, |
79 | | - ); |
80 | | -} |
81 | | - |
82 | 39 | test.describe('report replay-all', () => { |
83 | 40 | test.setTimeout(TEST_TIMEOUT); |
84 | 41 |
|
@@ -140,34 +97,8 @@ test.describe('report replay-all', () => { |
140 | 97 | .innerText(); |
141 | 98 | const { currentSeconds: initialSeconds, totalSeconds } = |
142 | 99 | parsePlaybackTime(initialTimeText.trim()); |
143 | | - const completionTimeoutMs = Math.max( |
144 | | - PLAYBACK_COMPLETE_TIMEOUT, |
145 | | - (totalSeconds + 5) * 5_000, |
146 | | - ); |
147 | | - |
148 | | - const advancedSeconds = await waitForPlaybackToAdvance(async () => { |
149 | | - const timeText = await reportPage |
150 | | - .locator(TIME_DISPLAY_SELECTOR) |
151 | | - .innerText(); |
152 | | - return parsePlaybackTime(timeText.trim()).currentSeconds; |
153 | | - }, initialSeconds); |
154 | | - |
155 | | - await waitForPlaybackToReach( |
156 | | - async () => { |
157 | | - const timeText = await reportPage |
158 | | - .locator(TIME_DISPLAY_SELECTOR) |
159 | | - .innerText(); |
160 | | - return parsePlaybackTime(timeText.trim()).currentSeconds; |
161 | | - }, |
162 | | - Math.max(advancedSeconds + 1, totalSeconds), |
163 | | - completionTimeoutMs, |
164 | | - ); |
165 | | - |
166 | | - await sleep(1_000); |
167 | | - |
168 | | - await reportAgent.aiAssert( |
169 | | - 'Only inspect the large replay player in the main content area. It is now showing the final search results page for "Hello world".', |
170 | | - ); |
| 100 | + expect(totalSeconds).toBeGreaterThan(0); |
| 101 | + expect(initialSeconds).toBeLessThan(totalSeconds); |
171 | 102 |
|
172 | 103 | expect(existsSync(validationReportPath)).toBe(true); |
173 | 104 | console.log('Source report file:', reportFile); |
|
0 commit comments