()
| 2698 | error_logs: list[str] = [] |
| 2699 | |
| 2700 | async def run_playwright(): |
| 2701 | async with async_playwright() as p: |
| 2702 | browser = await p.chromium.launch(headless=headless) |
| 2703 | page = await browser.new_page() |
| 2704 | |
| 2705 | # Setup console log capture |
| 2706 | def handle_console(msg: Any): |
| 2707 | timestamp = time.strftime("%H:%M:%S") |
| 2708 | log_entry = f"[{timestamp}] {msg.type}: {msg.text}" |
| 2709 | console_logs.append(log_entry) |
| 2710 | if msg.type in ["error", "warning"]: |
| 2711 | error_logs.append(log_entry) |
| 2712 | |
| 2713 | page.on("console", handle_console) |
| 2714 | |
| 2715 | # Setup error handlers |
| 2716 | page.on( |
| 2717 | "pageerror", lambda err: error_logs.append(f"Page Error: {err}") |
| 2718 | ) |
| 2719 | |
| 2720 | try: |
| 2721 | # Navigate to the page |
| 2722 | await page.goto(f"http://localhost:{port}", timeout=30000) |
| 2723 | |
| 2724 | # Wait for FastLED to initialize and render frames. |
| 2725 | # The Vite-bundled fastled_callbacks.ts increments |
| 2726 | # globalThis.fastLEDFrameCount on each frame automatically. |
| 2727 | await page.wait_for_timeout(5000) |
| 2728 | |
| 2729 | # Check if FastLED initialized |
| 2730 | frame_count = await page.evaluate( |
| 2731 | "globalThis.fastLEDFrameCount || 0" |
| 2732 | ) |
| 2733 | |
| 2734 | # Capture for specified duration |
| 2735 | await page.wait_for_timeout(capture_duration * 1000) |
| 2736 | |
| 2737 | # Take screenshot if requested |
| 2738 | screenshot_path = None |
| 2739 | if save_screenshot: |
| 2740 | screenshot_path = ( |
| 2741 | fastled_js_dir / f"fastled_capture_{int(time.time())}.png" |
| 2742 | ) |
| 2743 | await page.screenshot(path=str(screenshot_path)) |
| 2744 | |
| 2745 | return frame_count, screenshot_path |
| 2746 | |
| 2747 | finally: |
| 2748 | await browser.close() |
| 2749 | |
| 2750 | # Run the playwright automation |
| 2751 | frame_count, screenshot_path = await run_playwright() |
no test coverage detected