-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_graphical_about_app.py
More file actions
160 lines (129 loc) · 5.17 KB
/
test_graphical_about_app.py
File metadata and controls
160 lines (129 loc) · 5.17 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
"""
Graphical test for the About app.
This test verifies that the About app displays correct information,
specifically that the Hardware ID shown matches the actual hardware ID.
This is a proof of concept for graphical testing that:
1. Starts an app programmatically
2. Verifies UI content via direct widget inspection
3. Works on both desktop and device
Usage:
Desktop: ./tests/unittest.sh tests/test_graphical_about_app.py
Device: ./tests/unittest.sh tests/test_graphical_about_app.py --ondevice
"""
import unittest
import time
import lvgl as lv
import mpos.ui
from mpos import (
wait_for_render,
find_label_with_text,
verify_text_present,
print_screen_labels,
DeviceInfo,
BuildInfo,
AppManager,
)
class TestGraphicalAboutApp(unittest.TestCase):
"""Test suite for About app graphical verification."""
def _wait_for_text(self, text, attempts=6, render_iterations=30):
for attempt in range(1, attempts + 1):
screen = lv.screen_active()
print(f"\nText check attempt {attempt}/{attempts}:")
print_screen_labels(screen)
if verify_text_present(screen, text):
return True
wait_for_render(iterations=render_iterations)
time.sleep(0.2)
return False
def _wait_for_label_with_text(self, text, attempts=6, render_iterations=30):
for attempt in range(1, attempts + 1):
screen = lv.screen_active()
label = find_label_with_text(screen, text)
if label is not None:
return label
print(f"\nLabel '{text}' not found (attempt {attempt}/{attempts}).")
print_screen_labels(screen)
wait_for_render(iterations=render_iterations)
time.sleep(0.2)
return None
def setUp(self):
"""Set up test fixtures before each test method."""
# Store hardware ID for verification
self.hardware_id = DeviceInfo.hardware_id
print(f"Testing with hardware ID: {self.hardware_id}")
def tearDown(self):
"""Clean up after each test method."""
# Navigate back to launcher (closes the About app)
try:
mpos.ui.back_screen()
wait_for_render(5) # Allow navigation to complete
except:
pass # Already on launcher or error
def test_about_app_shows_correct_hardware_id(self):
"""
Test that About app displays the correct Hardware ID.
Verification approach:
1. Start the About app
2. Wait for UI to render
3. Find the "Hardware ID:" label
4. Verify it contains the actual hardware ID
"""
print("\n=== Starting About app test ===")
# Start the About app
result = AppManager.start_app("com.micropythonos.about")
self.assertTrue(result, "Failed to start About app")
# Wait for UI to fully render
wait_for_render(iterations=30)
# Get current screen
screen = lv.screen_active()
# Debug: Print all labels found (helpful for development)
print("\nLabels found on screen:")
print_screen_labels(screen)
# Verify that Hardware ID text is present
hardware_id_label = self._wait_for_label_with_text("Hardware ID:")
self.assertIsNotNone(
hardware_id_label,
"Could not find 'Hardware ID:' label on screen"
)
# Get the full text from the Hardware ID label
hardware_id_text = hardware_id_label.get_text()
print(f"\nHardware ID label text: {hardware_id_text}")
# Verify the hardware ID matches
expected_text = f"Hardware ID: {self.hardware_id}"
self.assertEqual(
hardware_id_text,
expected_text,
f"Hardware ID mismatch. Expected '{expected_text}', got '{hardware_id_text}'"
)
# Also verify using the helper function
self.assertTrue(
self._wait_for_text(self.hardware_id),
f"Hardware ID '{self.hardware_id}' not found on screen"
)
print("\n=== About app test completed successfully ===")
def test_about_app_shows_os_version(self):
"""
Test that About app displays the OS version.
This is a simpler test that just verifies version info is present.
"""
print("\n=== Starting About app OS version test ===")
# Start the About app
result = AppManager.start_app("com.micropythonos.about")
self.assertTrue(result, "Failed to start About app")
# Wait for UI to render
wait_for_render(iterations=150)
# Get current screen
screen = lv.screen_active()
# Verify that MicroPythonOS version text is present
self.assertTrue(
self._wait_for_text("Release version:"),
"Could not find 'Release version:' on screen"
)
# Verify the actual version string is present
os_version = BuildInfo.version.release
self.assertTrue(
self._wait_for_text(os_version),
f"OS version '{os_version}' not found on screen"
)
print(f"Found OS version: {os_version}")
print("=== OS version test completed successfully ===")