Spaces:
Sleeping
Sleeping
Create test_server.py
Browse files- test_server.py +92 -0
test_server.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test script for the browser-use server
|
4 |
+
Run this to test the server locally before deployment
|
5 |
+
"""
|
6 |
+
|
7 |
+
import requests
|
8 |
+
import json
|
9 |
+
import time
|
10 |
+
|
11 |
+
# Server URL (change this to your deployed URL when testing on Hugging Face Spaces)
|
12 |
+
BASE_URL = "http://localhost:7860"
|
13 |
+
|
14 |
+
def test_health():
|
15 |
+
"""Test the health endpoint"""
|
16 |
+
print("Testing /health endpoint...")
|
17 |
+
try:
|
18 |
+
response = requests.get(f"{BASE_URL}/health")
|
19 |
+
print(f"Status: {response.status_code}")
|
20 |
+
print(f"Response: {response.json()}")
|
21 |
+
return response.status_code == 200
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Error: {e}")
|
24 |
+
return False
|
25 |
+
|
26 |
+
def test_status():
|
27 |
+
"""Test the status endpoint"""
|
28 |
+
print("\nTesting /status endpoint...")
|
29 |
+
try:
|
30 |
+
response = requests.get(f"{BASE_URL}/status")
|
31 |
+
print(f"Status: {response.status_code}")
|
32 |
+
print(f"Response: {json.dumps(response.json(), indent=2)}")
|
33 |
+
return response.status_code == 200
|
34 |
+
except Exception as e:
|
35 |
+
print(f"Error: {e}")
|
36 |
+
return False
|
37 |
+
|
38 |
+
def test_run_task():
|
39 |
+
"""Test the run-task endpoint"""
|
40 |
+
print("\nTesting /run-task endpoint...")
|
41 |
+
try:
|
42 |
+
task_data = {
|
43 |
+
"task": "Go to example.com and get the page title",
|
44 |
+
"model": "gpt-4o-mini"
|
45 |
+
}
|
46 |
+
|
47 |
+
print(f"Sending task: {task_data}")
|
48 |
+
response = requests.post(
|
49 |
+
f"{BASE_URL}/run-task",
|
50 |
+
json=task_data,
|
51 |
+
timeout=60 # 1 minute timeout for testing
|
52 |
+
)
|
53 |
+
|
54 |
+
print(f"Status: {response.status_code}")
|
55 |
+
print(f"Response: {json.dumps(response.json(), indent=2)}")
|
56 |
+
return response.status_code == 200
|
57 |
+
except Exception as e:
|
58 |
+
print(f"Error: {e}")
|
59 |
+
return False
|
60 |
+
|
61 |
+
def main():
|
62 |
+
"""Run all tests"""
|
63 |
+
print("Browser-Use Server Test Suite")
|
64 |
+
print("=" * 40)
|
65 |
+
|
66 |
+
# Test basic endpoints
|
67 |
+
health_ok = test_health()
|
68 |
+
status_ok = test_status()
|
69 |
+
|
70 |
+
if not (health_ok and status_ok):
|
71 |
+
print("\n❌ Basic endpoints failed. Check if server is running and configured properly.")
|
72 |
+
return
|
73 |
+
|
74 |
+
# Test the main functionality
|
75 |
+
print("\n" + "=" * 40)
|
76 |
+
print("Testing browser automation (this may take a while)...")
|
77 |
+
task_ok = test_run_task()
|
78 |
+
|
79 |
+
print("\n" + "=" * 40)
|
80 |
+
print("Test Results:")
|
81 |
+
print(f"Health endpoint: {'✅' if health_ok else '❌'}")
|
82 |
+
print(f"Status endpoint: {'✅' if status_ok else '❌'}")
|
83 |
+
print(f"Task execution: {'✅' if task_ok else '❌'}")
|
84 |
+
|
85 |
+
if health_ok and status_ok and task_ok:
|
86 |
+
print("\n🎉 All tests passed! Your browser-use server is working correctly.")
|
87 |
+
else:
|
88 |
+
print("\n⚠️ Some tests failed. Check the error messages above.")
|
89 |
+
|
90 |
+
if __name__ == "__main__":
|
91 |
+
main()
|
92 |
+
|