|
10 | 10 | """ |
11 | 11 |
|
12 | 12 | import unittest |
13 | | -import time |
14 | 13 | import lvgl as lv |
15 | 14 | import mpos.ui |
16 | 15 | from mpos import ( |
|
28 | 27 | class TestGraphicalHotspotThenStation(unittest.TestCase): |
29 | 28 | """Test hotspot start flow via the hotspot settings app.""" |
30 | 29 |
|
| 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 | + |
31 | 50 | def _find_first_list_item(self, screen): |
32 | 51 | def find_list(node): |
33 | 52 | try: |
@@ -55,9 +74,24 @@ def find_list(node): |
55 | 74 | if wifi_list is None: |
56 | 75 | return None |
57 | 76 | try: |
58 | | - if wifi_list.get_child_count() < 1: |
| 77 | + child_count = wifi_list.get_child_count() |
| 78 | + if child_count < 1: |
59 | 79 | 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 |
61 | 95 | except Exception: |
62 | 96 | return None |
63 | 97 |
|
@@ -118,14 +152,16 @@ def test_hotspot_start_button_enables_hotspot(self): |
118 | 152 | print("\nWiFi screen labels (before scan wait):") |
119 | 153 | print_screen_labels(screen) |
120 | 154 |
|
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 | + ) |
123 | 160 |
|
124 | 161 | screen = lv.screen_active() |
125 | 162 | print("\nWiFi screen labels (after scan wait):") |
126 | 163 | print_screen_labels(screen) |
127 | 164 |
|
128 | | - first_item = self._find_first_list_item(screen) |
129 | 165 | self.assertIsNotNone(first_item, "Could not find first WiFi access point") |
130 | 166 |
|
131 | 167 | coords = get_widget_coords(first_item) |
|
0 commit comments