283 lines
9.2 KiB
Python
283 lines
9.2 KiB
Python
#!/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)
|