-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_visual_api.py
More file actions
165 lines (142 loc) · 5.92 KB
/
test_visual_api.py
File metadata and controls
165 lines (142 loc) · 5.92 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
"""
Test script for Tinker Browser Visual Testing API
"""
import requests
import json
import time
API_BASE = "http://127.0.0.1:3003"
def test_screenshot():
"""Test screenshot capture"""
print("📸 Testing screenshot capture...")
try:
payload = {
"options": {
"format": "PNG",
"quality": 90
}
}
response = requests.post(f"{API_BASE}/api/screenshot",
json=payload,
headers={"Content-Type": "application/json"},
timeout=10)
print(f"✅ Screenshot: {response.status_code}")
print(f" Response: {response.json()}")
return response.status_code == 200
except Exception as e:
print(f"❌ Screenshot failed: {e}")
return False
def test_create_baseline():
"""Test baseline creation"""
print("\n📏 Testing baseline creation...")
try:
payload = {
"test_name": "homepage_test",
"options": {
"format": "PNG"
}
}
response = requests.post(f"{API_BASE}/api/visual/baseline",
json=payload,
headers={"Content-Type": "application/json"},
timeout=10)
print(f"✅ Create baseline: {response.status_code}")
print(f" Response: {response.json()}")
return response.status_code == 200
except Exception as e:
print(f"❌ Baseline creation failed: {e}")
return False
def test_visual_regression():
"""Test visual regression testing"""
print("\n🔍 Testing visual regression...")
try:
payload = {
"test_name": "homepage_test",
"tolerance": 0.05, # 5% tolerance
"options": {
"format": "PNG"
}
}
response = requests.post(f"{API_BASE}/api/visual/test",
json=payload,
headers={"Content-Type": "application/json"},
timeout=10)
print(f"✅ Visual test: {response.status_code}")
print(f" Response: {response.json()}")
return response.status_code == 200
except Exception as e:
print(f"❌ Visual test failed: {e}")
return False
def test_enhanced_capabilities():
"""Test enhanced browser info with visual capabilities"""
print("\n🔍 Testing enhanced browser capabilities...")
try:
response = requests.get(f"{API_BASE}/api/info", timeout=5)
print(f"✅ Enhanced info: {response.status_code}")
data = response.json()
capabilities = data.get('data', {}).get('capabilities', [])
visual_caps = [cap for cap in capabilities if 'visual' in cap or 'screenshot' in cap]
print(f" Visual capabilities: {visual_caps}")
endpoints = data.get('data', {}).get('endpoints', {})
visual_endpoints = {k: v for k, v in endpoints.items() if 'screenshot' in k or 'visual' in k}
print(f" Visual endpoints: {visual_endpoints}")
return len(visual_caps) > 0
except Exception as e:
print(f"❌ Enhanced info failed: {e}")
return False
def test_navigation_with_visual():
"""Test navigation followed by screenshot"""
print("\n🧭 Testing navigation + screenshot workflow...")
try:
# Navigate to a different page
nav_payload = {"url": "https://www.rust-lang.org"}
nav_response = requests.post(f"{API_BASE}/api/navigate",
json=nav_payload,
headers={"Content-Type": "application/json"},
timeout=5)
print(f"✅ Navigation: {nav_response.status_code}")
# Wait a moment for navigation
time.sleep(2)
# Take screenshot of new page
screenshot_payload = {"options": {"format": "JPEG", "quality": 80}}
screenshot_response = requests.post(f"{API_BASE}/api/screenshot",
json=screenshot_payload,
headers={"Content-Type": "application/json"},
timeout=10)
print(f"✅ Post-navigation screenshot: {screenshot_response.status_code}")
return nav_response.status_code == 200 and screenshot_response.status_code == 200
except Exception as e:
print(f"❌ Navigation + screenshot workflow failed: {e}")
return False
def main():
"""Run all visual testing API tests"""
print("🎨 Testing Tinker Browser Visual Testing API")
print("=" * 60)
results = []
# Test enhanced capabilities first
results.append(test_enhanced_capabilities())
# Test basic screenshot functionality
results.append(test_screenshot())
# Test baseline creation
results.append(test_create_baseline())
# Test visual regression testing
results.append(test_visual_regression())
# Test navigation + screenshot workflow
results.append(test_navigation_with_visual())
# Summary
print("\n" + "=" * 60)
passed = sum(results)
total = len(results)
print(f"📊 Visual Testing Results: {passed}/{total} passed")
if passed == total:
print("🎉 All visual testing features working perfectly!")
print("🚀 Tinker now has complete visual testing capabilities:")
print(" • Screenshot capture with multiple formats")
print(" • Baseline creation for regression testing")
print(" • Visual comparison with configurable tolerance")
print(" • Integration with browser navigation")
else:
print("⚠️ Some visual tests failed. Check if Tinker is running with --api flag")
return passed == total
if __name__ == "__main__":
main()