Files
broswer-automation/agent-livekit/test_qubecare_login.py
nasir@endelospay.com d97cad1736 first commit
2025-08-12 02:54:17 +05:00

158 lines
5.6 KiB
Python

#!/usr/bin/env python3
"""
Test script for QuBeCare login functionality
"""
import asyncio
import logging
import sys
import os
from mcp_chrome_client import MCPChromeClient
# Simple config for testing
def get_test_config():
return {
'mcp_server_type': 'http',
'mcp_server_url': 'http://127.0.0.1:12306/mcp',
'mcp_server_command': None,
'mcp_server_args': []
}
async def test_qubecare_login():
"""Test QuBeCare login form filling"""
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# Test credentials (replace with actual test credentials)
test_email = "test@example.com" # Replace with your test email
test_password = "test_password" # Replace with your test password
# Initialize MCP Chrome client
config = get_test_config()
client = MCPChromeClient(config)
try:
logger.info("🚀 Starting QuBeCare login test...")
# Step 1: Navigate to QuBeCare login page
logger.info("📍 Step 1: Navigating to QuBeCare login page...")
result = await client._navigate_mcp("https://app.qubecare.ai/provider/login")
logger.info(f"Navigation result: {result}")
# Step 2: Wait for page to load
logger.info("⏳ Step 2: Waiting for page to load...")
await asyncio.sleep(5) # Give page time to load completely
# Step 3: Detect form fields
logger.info("🔍 Step 3: Detecting form fields...")
form_fields = await client.get_form_fields()
logger.info(f"Form fields detected:\n{form_fields}")
# Step 4: Try QuBeCare-specific login method
logger.info("🔐 Step 4: Attempting QuBeCare login...")
login_result = await client.fill_qubecare_login(test_email, test_password)
logger.info(f"Login filling result:\n{login_result}")
# Step 5: Check if fields were filled
logger.info("✅ Step 5: Verifying form filling...")
# Try to get current field values to verify filling
try:
verification_script = """
const inputs = document.querySelectorAll('input');
const results = [];
inputs.forEach((input, index) => {
results.push({
index: index,
type: input.type,
name: input.name,
id: input.id,
value: input.value ? '***filled***' : 'empty',
placeholder: input.placeholder
});
});
return results;
"""
verification = await client._call_mcp_tool("chrome_execute_script", {
"script": verification_script
})
logger.info(f"Field verification:\n{verification}")
except Exception as e:
logger.warning(f"Could not verify field values: {e}")
# Step 6: Optional - Try to submit form (commented out for safety)
# logger.info("📤 Step 6: Attempting form submission...")
# submit_result = await client.submit_form()
# logger.info(f"Submit result: {submit_result}")
logger.info("✅ Test completed successfully!")
# Summary
print("\n" + "="*60)
print("QUBECARE LOGIN TEST SUMMARY")
print("="*60)
print(f"✅ Navigation: {'Success' if 'successfully' in result.lower() else 'Failed'}")
print(f"✅ Form Detection: {'Success' if 'found' in form_fields.lower() and 'no form fields found' not in form_fields.lower() else 'Failed'}")
print(f"✅ Login Filling: {'Success' if 'successfully' in login_result.lower() else 'Partial/Failed'}")
print("="*60)
if "no form fields found" in form_fields.lower():
print("\n⚠️ WARNING: No form fields detected!")
print("This could indicate:")
print("- Page is still loading")
print("- Form is in an iframe or shadow DOM")
print("- JavaScript is required to render the form")
print("- The page structure has changed")
print("\nTry running the debug script: python debug_form_detection.py")
return True
except Exception as e:
logger.error(f"❌ Test failed with error: {e}")
return False
finally:
# Clean up
try:
await client.close()
except:
pass
async def quick_debug():
"""Quick debug function to check basic connectivity"""
config = get_test_config()
client = MCPChromeClient(config)
try:
# Just try to navigate and see what happens
result = await client._navigate_mcp("https://app.qubecare.ai/provider/login")
print(f"Quick navigation test: {result}")
await asyncio.sleep(2)
# Try to get page title
title_result = await client._call_mcp_tool("chrome_execute_script", {
"script": "return document.title"
})
print(f"Page title: {title_result}")
except Exception as e:
print(f"Quick debug failed: {e}")
finally:
try:
await client.close()
except:
pass
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "quick":
print("Running quick debug...")
asyncio.run(quick_debug())
else:
print("Running full QuBeCare login test...")
print("Note: Update test_email and test_password variables before running!")
asyncio.run(test_qubecare_login())