#!/usr/bin/env python3
# Hermes Node Protocol
# Copyright (c) 2026 Stefy (nextime) Lanza <stefy@nexlab.net>
# All rights reserved.
# 
# This software is released under the MIT License with a copyleft clause.
# See the LICENSE file for full terms.
"""Test browser controller"""
import asyncio
from browser_controller import BrowserController

async def test():
    controller = BrowserController()
    
    try:
        print("Initializing Playwright...")
        await controller.initialize()
        print("✅ Playwright initialized")
        
        print("\nLaunching browser (headless)...")
        result = await controller.launch({"headless": True})
        print(f"✅ {result}")
        
        print("\nCreating context...")
        result = await controller.create_context({"name": "test_ctx"})
        print(f"✅ {result}")
        page_id = result.get("page_id")
        
        print(f"\nNavigating to example.com (page_id={page_id})...")
        result = await controller.navigate(page_id, "https://example.com")
        print(f"✅ {result}")
        
        print("\nGetting title...")
        result = await controller.get_title(page_id)
        print(f"✅ {result}")
        
        print("\nTaking screenshot...")
        result = await controller.screenshot(page_id, full_page=True)
        print(f"✅ Screenshot captured ({len(result.get('screenshot', ''))} chars base64)")
        
        print("\nClosing browser...")
        await controller.close()
        print("✅ Browser closed")
        
        print("\n🎉 All tests passed!")
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test())
