-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_with_device.py
More file actions
243 lines (200 loc) · 7.34 KB
/
test_with_device.py
File metadata and controls
243 lines (200 loc) · 7.34 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python3
"""
Comprehensive test script for Windscribe IP Changer with device connection
"""
import subprocess
import sys
import os
from windscribe_ip_changer import WindscribeIPChanger
def check_adb_installation():
"""Check if ADB is installed and accessible"""
print("=== Checking ADB Installation ===")
# Check common locations
common_paths = [
"/usr/bin/adb",
"/usr/local/bin/adb",
os.path.join(os.path.expanduser("~"), "Android/Sdk/platform-tools/adb"),
"/opt/android-sdk/platform-tools/adb",
]
found_paths = []
for path in common_paths:
if os.path.isfile(path) and os.access(path, os.X_OK):
found_paths.append(path)
print(f"✓ Found ADB at: {path}")
# Try which command
try:
result = subprocess.run(
["which", "adb"],
capture_output=True,
text=True
)
if result.returncode == 0 and result.stdout:
adb_path = result.stdout.strip()
if adb_path not in found_paths:
found_paths.append(adb_path)
print(f"✓ Found ADB in PATH: {adb_path}")
except:
pass
if not found_paths:
print("✗ ADB not found!")
print("\nTo install ADB on Arch Linux:")
print(" sudo pacman -S android-tools")
print("\nOr download Android SDK Platform Tools:")
print(" https://developer.android.com/studio/releases/platform-tools")
return None
return found_paths[0] if found_paths else None
def test_device_connection(adb_path):
"""Test connection to Android device"""
print("\n=== Testing Device Connection ===")
changer = WindscribeIPChanger(adb_path=adb_path)
# List devices
devices = changer.list_devices()
if not devices:
print("✗ No devices connected!")
print("\nPlease:")
print(" 1. Connect your Android device via USB")
print(" 2. Enable USB Debugging in Developer Options")
print(" 3. Accept the debugging prompt on your device")
print(" 4. Run: adb devices")
return False
print(f"✓ Found {len(devices)} device(s):")
for device in devices:
print(f" - {device['device_id']} ({device['status']})")
# Test connection
if changer.check_adb_connection():
print("✓ ADB connection verified")
device_id = changer.get_connected_device()
print(f" Using device: {device_id}")
return True, changer, device_id
else:
print("✗ ADB connection check failed")
return False, None, None
def test_screen_detection(changer):
"""Test screen size detection"""
print("\n=== Testing Screen Detection ===")
try:
screen_width, screen_height = changer._get_screen_size()
print(f"✓ Screen size: {screen_width}x{screen_height}")
print(f" Center: ({screen_width // 2}, {screen_height // 2})")
return True
except Exception as e:
print(f"✗ Screen detection failed: {e}")
return False
def test_windscribe_detection(changer):
"""Test Windscribe app detection"""
print("\n=== Testing Windscribe Detection ===")
if not changer.check_windscribe_installed():
print("✗ Windscribe not found!")
print("\nPlease install Windscribe app from Google Play Store")
return False
print("✓ Windscribe found")
package = changer.get_windscribe_package_name()
if package:
print(f" Package: {package}")
print(" Type: Android App (UI automation enabled)")
else:
print(" Type: CLI")
status = changer.get_windscribe_status()
if status:
print(f" Status: {status}")
else:
print(" Status: Not connected")
ip = changer.get_current_ip()
if ip:
print(f" Current IP: {ip}")
else:
print(" IP: Could not determine")
return True
def test_ui_automation(changer):
"""Test UI automation capabilities"""
print("\n=== Testing UI Automation Capabilities ===")
package = changer.get_windscribe_package_name()
if not package:
print(" UI automation: Not needed (CLI mode)")
return True
print("✓ UI automation methods available:")
print(" - Screen size detection: ✓")
print(" - Tap simulation: ✓")
print(" - Text input: ✓")
print(" - Swipe simulation: ✓")
print(" - UI hierarchy detection: ✓")
# Test tap functionality
try:
screen_width, screen_height = changer._get_screen_size()
center_x = screen_width // 2
center_y = screen_height // 2
print(f"\n Testing tap at ({center_x}, {center_y})...")
if changer._tap(center_x, center_y):
print(" ✓ Tap command executed successfully")
else:
print(" ⚠ Tap command may have failed")
except Exception as e:
print(f" ✗ Tap test failed: {e}")
return True
def test_connection_flow(changer):
"""Test the connection/disconnection flow"""
print("\n=== Testing Connection Flow ===")
package = changer.get_windscribe_package_name()
if not package:
print(" Skipping (CLI mode - requires manual testing)")
return True
print(" This will test the full UI automation flow...")
print(" Note: This will interact with the Windscribe app")
response = input(" Proceed with connection test? (y/N): ").strip().lower()
if response != 'y':
print(" Skipped by user")
return True
# Test disconnect first
print("\n Testing disconnect...")
if changer.disconnect_windscribe():
print(" ✓ Disconnect completed")
else:
print(" ⚠ Disconnect may have failed")
time.sleep(2)
# Test connect to a location
print("\n Testing connect to 'us-east'...")
if changer.connect_windscribe("us-east"):
print(" ✓ Connection completed")
# Verify connection
time.sleep(3)
status = changer.get_windscribe_status()
ip = changer.get_current_ip()
print(f" Status: {status}")
print(f" IP: {ip}")
else:
print(" ✗ Connection failed")
return False
return True
def main():
"""Run all tests"""
print("=" * 60)
print("Windscribe IP Changer - Device Testing")
print("=" * 60)
# Step 1: Check ADB
adb_path = check_adb_installation()
if not adb_path:
print("\n✗ Cannot proceed without ADB")
sys.exit(1)
# Step 2: Test device connection
result = test_device_connection(adb_path)
if not result:
print("\n✗ Cannot proceed without connected device")
sys.exit(1)
success, changer, device_id = result
# Step 3: Test screen detection
if not test_screen_detection(changer):
print("\n⚠ Screen detection failed, but continuing...")
# Step 4: Test Windscribe detection
if not test_windscribe_detection(changer):
print("\n✗ Windscribe not found - install the app first")
sys.exit(1)
# Step 5: Test UI automation
test_ui_automation(changer)
# Step 6: Test connection flow (optional)
import time
test_connection_flow(changer)
print("\n" + "=" * 60)
print("✓ All tests completed!")
print("=" * 60)
if __name__ == "__main__":
main()