#!/usr/bin/env python3 """ QuBeCare Voice Test - Live Agent Testing This script provides a simple way to test the LiveKit agent with QuBeCare login using voice commands. """ import asyncio import logging import sys import os from pathlib import Path # Add current directory to path for imports sys.path.insert(0, str(Path(__file__).parent)) from mcp_chrome_client import MCPChromeClient async def test_qubecare_login(): """Test QuBeCare login with voice commands""" print("šŸŽ¤ QUBECARE VOICE COMMAND TEST") print("=" * 50) print("This script will test voice commands on QuBeCare login page") print("Make sure your Chrome MCP server is running!") print("=" * 50) # Get test credentials print("\nšŸ“ Enter test credentials:") username = input("Username (or press Enter for demo@example.com): ").strip() if not username: username = "demo@example.com" password = input("Password (or press Enter for demo123): ").strip() if not password: password = "demo123" print(f"\nšŸ”‘ Using credentials: {username} / {'*' * len(password)}") # Initialize MCP client chrome_config = { 'mcp_server_type': 'http', 'mcp_server_url': 'http://127.0.0.1:12306/mcp', 'mcp_server_command': None, 'mcp_server_args': [] } mcp_client = MCPChromeClient(chrome_config) try: print("\nšŸ”Œ Connecting to Chrome MCP server...") await mcp_client.connect() print("āœ… Connected successfully!") # Step 1: Navigate to QuBeCare print("\n🌐 Step 1: Navigating to QuBeCare...") nav_result = await mcp_client.process_natural_language_command( "navigate to https://app.qubecare.ai/provider/login" ) print(f"šŸ“ Navigation: {nav_result}") # Wait for page load print("ā³ Waiting for page to load...") await asyncio.sleep(4) # Step 2: Analyze the page print("\nšŸ” Step 2: Analyzing page structure...") # Get form fields fields_result = await mcp_client.process_natural_language_command("show me form fields") print(f"šŸ“‹ Form fields: {fields_result}") # Get interactive elements elements_result = await mcp_client.process_natural_language_command("what can I click") print(f"šŸ–±ļø Clickable elements: {elements_result}") # Step 3: Fill username print(f"\nšŸ‘¤ Step 3: Filling username ({username})...") username_commands = [ f"fill email with {username}", f"enter {username} in email", f"type {username} in username field", f"email {username}" ] username_success = False for cmd in username_commands: print(f"šŸ—£ļø Trying: '{cmd}'") try: result = await mcp_client.process_natural_language_command(cmd) print(f"šŸ“¤ Result: {result}") if "success" in result.lower() or "filled" in result.lower(): print("āœ… Username filled successfully!") username_success = True break await asyncio.sleep(1) except Exception as e: print(f"āŒ Error: {e}") # Step 4: Fill password print(f"\nšŸ”’ Step 4: Filling password...") password_commands = [ f"fill password with {password}", f"enter {password} in password", f"type {password} in password field", f"password {password}" ] password_success = False for cmd in password_commands: print(f"šŸ—£ļø Trying: '{cmd}'") try: result = await mcp_client.process_natural_language_command(cmd) print(f"šŸ“¤ Result: {result}") if "success" in result.lower() or "filled" in result.lower(): print("āœ… Password filled successfully!") password_success = True break await asyncio.sleep(1) except Exception as e: print(f"āŒ Error: {e}") # Step 5: Click login button print(f"\nšŸ”˜ Step 5: Clicking login button...") login_commands = [ "click login button", "press login", "click sign in", "login", "sign in", "click submit" ] login_success = False for cmd in login_commands: print(f"šŸ—£ļø Trying: '{cmd}'") try: result = await mcp_client.process_natural_language_command(cmd) print(f"šŸ“¤ Result: {result}") if "success" in result.lower() or "clicked" in result.lower(): print("āœ… Login button clicked successfully!") login_success = True break await asyncio.sleep(1) except Exception as e: print(f"āŒ Error: {e}") # Final summary print("\nšŸ“Š TEST RESULTS SUMMARY") print("=" * 40) print(f"🌐 Navigation: āœ… Success") print(f"šŸ‘¤ Username: {'āœ… Success' if username_success else 'āŒ Failed'}") print(f"šŸ”’ Password: {'āœ… Success' if password_success else 'āŒ Failed'}") print(f"šŸ”˜ Login Click: {'āœ… Success' if login_success else 'āŒ Failed'}") print("=" * 40) if username_success and password_success and login_success: print("šŸŽ‰ ALL TESTS PASSED! Voice commands working perfectly!") elif username_success or password_success: print("āš ļø PARTIAL SUCCESS - Some voice commands worked") else: print("āŒ TESTS FAILED - Voice commands need adjustment") # Wait a moment to see results print("\nā³ Waiting 5 seconds to observe results...") await asyncio.sleep(5) except Exception as e: print(f"āŒ Test failed with error: {e}") finally: print("\nšŸ”Œ Disconnecting from MCP server...") await mcp_client.disconnect() print("šŸ‘‹ Test completed!") async def interactive_mode(): """Interactive mode for testing individual commands""" print("šŸŽ® INTERACTIVE QUBECARE TEST MODE") print("=" * 50) print("Navigate to QuBeCare and test individual voice commands") print("=" * 50) # Initialize MCP client chrome_config = { 'mcp_server_type': 'http', 'mcp_server_url': 'http://127.0.0.1:12306/mcp', 'mcp_server_command': None, 'mcp_server_args': [] } mcp_client = MCPChromeClient(chrome_config) try: await mcp_client.connect() print("āœ… Connected to Chrome MCP server") # Auto-navigate to QuBeCare print("🌐 Auto-navigating to QuBeCare...") await mcp_client.process_natural_language_command( "navigate to https://app.qubecare.ai/provider/login" ) await asyncio.sleep(3) print("āœ… Ready for voice commands!") print("\nšŸ’” Suggested commands:") print("- show me form fields") print("- what can I click") print("- fill email with your@email.com") print("- fill password with yourpassword") print("- click login button") print("- what's on this page") print("\nType 'quit' to exit") while True: try: command = input("\nšŸ—£ļø Voice command: ").strip() if command.lower() in ['quit', 'exit', 'q']: break elif not command: continue print(f"šŸ”„ Processing: {command}") result = await mcp_client.process_natural_language_command(command) print(f"āœ… Result: {result}") except KeyboardInterrupt: break except Exception as e: print(f"āŒ Error: {e}") except Exception as e: print(f"āŒ Connection failed: {e}") finally: await mcp_client.disconnect() print("šŸ‘‹ Interactive mode ended") async def main(): """Main function""" print("šŸŽ¤ QuBeCare Voice Command Tester") print("\nChoose mode:") print("1. Automated Test (full login sequence)") print("2. Interactive Mode (manual commands)") try: choice = input("\nEnter choice (1 or 2): ").strip() if choice == "1": await test_qubecare_login() elif choice == "2": await interactive_mode() else: print("Invalid choice. Please enter 1 or 2.") return 1 return 0 except KeyboardInterrupt: print("\nšŸ‘‹ Interrupted by user") return 0 except Exception as e: print(f"āŒ Error: {e}") return 1 if __name__ == "__main__": # Set up basic logging logging.basicConfig(level=logging.INFO) # Run the test exit_code = asyncio.run(main()) sys.exit(exit_code)