forked from uusense/python-devicebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenshot_hierarchy.py
More file actions
33 lines (24 loc) · 932 Bytes
/
Copy pathscreenshot_hierarchy.py
File metadata and controls
33 lines (24 loc) · 932 Bytes
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
"""Screenshots and UI hierarchy inspection."""
from devicebase import DeviceBaseClient
client = DeviceBaseClient(serial="device123")
# === Screenshots ===
# Get screenshot as raw JPEG bytes
screenshot_bytes = client.get_screenshot()
with open("screenshot.jpg", "wb") as f:
f.write(screenshot_bytes)
# Download as attachment (with filename)
attachment_bytes = client.download_screenshot()
with open("device123_screenshot.jpg", "wb") as f:
f.write(attachment_bytes)
# === UI Hierarchy ===
# Dump the current UI element tree
hierarchy = client.dump_hierarchy()
print(f"Hierarchy: {hierarchy.data}")
# === Combine: Screenshot + Hierarchy for automation ===
# Take screenshot before inspecting UI
screenshot = client.get_screenshot()
# Get UI hierarchy to find interactive elements
hierarchy = client.dump_hierarchy()
print(f"Screenshot size: {len(screenshot)} bytes")
print(f"UI tree: {hierarchy.data}")
client.close()