Skip to content

Commit 144f770

Browse files
Fix test
1 parent 04274b3 commit 144f770

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

tests/test_graphical_hotspot_then_station.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212
import unittest
13-
import time
1413
import lvgl as lv
1514
import mpos.ui
1615
from mpos import (
@@ -28,6 +27,26 @@
2827
class TestGraphicalHotspotThenStation(unittest.TestCase):
2928
"""Test hotspot start flow via the hotspot settings app."""
3029

30+
def _first_text_in_tree(self, node):
31+
try:
32+
if hasattr(node, "get_text"):
33+
text = node.get_text()
34+
if text:
35+
return text
36+
except Exception:
37+
pass
38+
39+
try:
40+
child_count = node.get_child_count()
41+
except Exception:
42+
return None
43+
44+
for i in range(child_count):
45+
text = self._first_text_in_tree(node.get_child(i))
46+
if text:
47+
return text
48+
return None
49+
3150
def _find_first_list_item(self, screen):
3251
def find_list(node):
3352
try:
@@ -55,9 +74,24 @@ def find_list(node):
5574
if wifi_list is None:
5675
return None
5776
try:
58-
if wifi_list.get_child_count() < 1:
77+
child_count = wifi_list.get_child_count()
78+
if child_count < 1:
5979
return None
60-
return wifi_list.get_child(0)
80+
81+
for idx in range(child_count):
82+
child = wifi_list.get_child(idx)
83+
text = self._first_text_in_tree(child)
84+
if not text:
85+
continue
86+
if text == "Add network":
87+
continue
88+
if "Scanning" in text:
89+
continue
90+
if "ERROR TEXT" in text:
91+
continue
92+
return child
93+
94+
return None
6195
except Exception:
6296
return None
6397

@@ -118,14 +152,16 @@ def test_hotspot_start_button_enables_hotspot(self):
118152
print("\nWiFi screen labels (before scan wait):")
119153
print_screen_labels(screen)
120154

121-
print("\nWaiting 10 seconds for WiFi scan to finish...")
122-
time.sleep(10)
155+
print("\nWaiting for first discovered access point...")
156+
first_item = wait_for_widget(
157+
lambda: self._find_first_list_item(lv.screen_active()),
158+
timeout=25,
159+
)
123160

124161
screen = lv.screen_active()
125162
print("\nWiFi screen labels (after scan wait):")
126163
print_screen_labels(screen)
127164

128-
first_item = self._find_first_list_item(screen)
129165
self.assertIsNotNone(first_item, "Could not find first WiFi access point")
130166

131167
coords = get_widget_coords(first_item)

0 commit comments

Comments
 (0)