File size: 2,785 Bytes
c80036e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
Test script for the browser-use server
Run this to test the server locally before deployment
"""

import requests
import json
import time

# Server URL (change this to your deployed URL when testing on Hugging Face Spaces)
BASE_URL = "http://localhost:7860"

def test_health():
    """Test the health endpoint"""
    print("Testing /health endpoint...")
    try:
        response = requests.get(f"{BASE_URL}/health")
        print(f"Status: {response.status_code}")
        print(f"Response: {response.json()}")
        return response.status_code == 200
    except Exception as e:
        print(f"Error: {e}")
        return False

def test_status():
    """Test the status endpoint"""
    print("\nTesting /status endpoint...")
    try:
        response = requests.get(f"{BASE_URL}/status")
        print(f"Status: {response.status_code}")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
        return response.status_code == 200
    except Exception as e:
        print(f"Error: {e}")
        return False

def test_run_task():
    """Test the run-task endpoint"""
    print("\nTesting /run-task endpoint...")
    try:
        task_data = {
            "task": "Go to example.com and get the page title",
            "model": "gpt-4o-mini"
        }
        
        print(f"Sending task: {task_data}")
        response = requests.post(
            f"{BASE_URL}/run-task",
            json=task_data,
            timeout=60  # 1 minute timeout for testing
        )
        
        print(f"Status: {response.status_code}")
        print(f"Response: {json.dumps(response.json(), indent=2)}")
        return response.status_code == 200
    except Exception as e:
        print(f"Error: {e}")
        return False

def main():
    """Run all tests"""
    print("Browser-Use Server Test Suite")
    print("=" * 40)
    
    # Test basic endpoints
    health_ok = test_health()
    status_ok = test_status()
    
    if not (health_ok and status_ok):
        print("\n❌ Basic endpoints failed. Check if server is running and configured properly.")
        return
    
    # Test the main functionality
    print("\n" + "=" * 40)
    print("Testing browser automation (this may take a while)...")
    task_ok = test_run_task()
    
    print("\n" + "=" * 40)
    print("Test Results:")
    print(f"Health endpoint: {'✅' if health_ok else '❌'}")
    print(f"Status endpoint: {'✅' if status_ok else '❌'}")
    print(f"Task execution: {'✅' if task_ok else '❌'}")
    
    if health_ok and status_ok and task_ok:
        print("\n🎉 All tests passed! Your browser-use server is working correctly.")
    else:
        print("\n⚠️  Some tests failed. Check the error messages above.")

if __name__ == "__main__":
    main()