73 lines
3.1 KiB
Python
73 lines
3.1 KiB
Python
import asyncio
|
|
from playwright.async_api import async_playwright
|
|
import sys
|
|
import time
|
|
|
|
async def main():
|
|
async with async_playwright() as p:
|
|
browser = await p.chromium.launch(headless=True)
|
|
page = await browser.new_page()
|
|
|
|
url = "http://localhost:5173/"
|
|
|
|
print("Testing frontend playback sync consistency on reload...")
|
|
times = []
|
|
wall_times = []
|
|
|
|
# Intercept console messages
|
|
page.on("console", lambda msg: print(f"BROWSER LOG: {msg.text}"))
|
|
|
|
for i in range(5):
|
|
start_wall = time.time()
|
|
await page.goto(url)
|
|
|
|
# Wait for the video element and for it to begin playing
|
|
try:
|
|
await page.wait_for_selector('video.tuner-video', state='attached', timeout=5000)
|
|
# wait 1 second to let metadata and ref execute
|
|
await page.wait_for_timeout(1000)
|
|
|
|
current_time = await page.evaluate("() => { const v = document.querySelector('video.tuner-video.playing'); return v ? v.currentTime : null; }")
|
|
current_src = await page.evaluate("() => { const v = document.querySelector('video.tuner-video.playing'); return v ? v.currentSrc : null; }")
|
|
|
|
if current_time is None:
|
|
print(f"Reload {i+1}: Video element found but currentTime is null")
|
|
continue
|
|
|
|
times.append(current_time)
|
|
wall_times.append(time.time() - start_wall)
|
|
print(f"Reload {i+1}: src = {current_src}, currentTime = {current_time:.2f} seconds")
|
|
|
|
except Exception as e:
|
|
print(f"Reload {i+1}: Error - {e}")
|
|
|
|
await browser.close()
|
|
|
|
if not times:
|
|
print("No times recorded. Ensure the frontend and backend are running.")
|
|
sys.exit(1)
|
|
|
|
diffs = [times[i] - times[i-1] for i in range(1, len(times))]
|
|
print("Differences in video time between loads:", [f"{d:.2f}s" for d in diffs])
|
|
|
|
# If the video restarts on reload, the current time will always be ~1.0 seconds (since we wait 1000ms).
|
|
# Normal behavior should have the time incrementing by the wall clock duration of the reload loop.
|
|
bug_present = False
|
|
for i, t in enumerate(times):
|
|
if t < 2.5: # Should definitely be higher than 2.5 after a few reloads if it started > 0, OR if it started near 0, subsequent ones should go up.
|
|
pass
|
|
|
|
# Actually, let's just check if the sequence of times is monotonically increasing
|
|
# given that the item is supposed to be continuous wall-clock time
|
|
is_monotonic = all(times[i] > times[i-1] for i in range(1, len(times)))
|
|
|
|
if not is_monotonic:
|
|
print("TEST FAILED: BUG REPRODUCED. The currentTime is not continuous across reloads.")
|
|
sys.exit(1)
|
|
else:
|
|
print("TEST PASSED: The currentTime is continuous across reloads.")
|
|
sys.exit(0)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|