2020 wait_for_render ,
2121 find_button_with_text ,
2222 get_widget_coords ,
23+ get_keyboard_button_coords ,
2324 simulate_click ,
2425 print_screen_labels
2526)
@@ -79,43 +80,16 @@ def test_q_button_works(self):
7980 # --- Test 'q' button ---
8081 print ("\n --- Testing 'q' button ---" )
8182
82- # Find button index for 'q' in the keyboard
83- q_button_id = None
84- for i in range (100 ): # Check first 100 button indices
85- try :
86- text = keyboard .get_button_text (i )
87- if text == "q" :
88- q_button_id = i
89- print (f"Found 'q' button at index { i } " )
90- break
91- except :
92- break # No more buttons
93-
94- self .assertIsNotNone (q_button_id , "Should find 'q' button on keyboard" )
95-
96- # Get the keyboard widget coordinates to calculate button position
97- keyboard_area = lv .area_t ()
98- keyboard .get_coords (keyboard_area )
99- print (f"Keyboard area: x1={ keyboard_area .x1 } , y1={ keyboard_area .y1 } , x2={ keyboard_area .x2 } , y2={ keyboard_area .y2 } " )
100-
101- # LVGL keyboards organize buttons in a grid
102- # From the map: "q" is at index 0, in top row (10 buttons per row)
103- # Let's estimate position based on keyboard layout
104- # Top row starts at y1 + some padding, each button is ~width/10
105- keyboard_width = keyboard_area .x2 - keyboard_area .x1
106- keyboard_height = keyboard_area .y2 - keyboard_area .y1
107- button_width = keyboard_width // 10 # ~10 buttons per row
108- button_height = keyboard_height // 4 # ~4 rows
109-
110- # 'q' is first button (index 0), top row
111- q_x = keyboard_area .x1 + button_width // 2
112- q_y = keyboard_area .y1 + button_height // 2
83+ # Get exact button coordinates using helper function
84+ q_coords = get_keyboard_button_coords (keyboard , "q" )
85+ self .assertIsNotNone (q_coords , "Should find 'q' button on keyboard" )
11386
114- print (f"Estimated 'q' button position: ({ q_x } , { q_y } )" )
87+ print (f"Found 'q' button at index { q_coords ['button_idx' ]} , row { q_coords ['row' ]} , col { q_coords ['col' ]} " )
88+ print (f"Exact 'q' button position: ({ q_coords ['center_x' ]} , { q_coords ['center_y' ]} )" )
11589
11690 # Click the 'q' button
117- print (f"Clicking 'q' button at ({ q_x } , { q_y } )" )
118- simulate_click (q_x , q_y )
91+ print (f"Clicking 'q' button at ({ q_coords [ 'center_x' ] } , { q_coords [ 'center_y' ] } )" )
92+ simulate_click (q_coords [ 'center_x' ], q_coords [ 'center_y' ] )
11993 wait_for_render (10 )
12094
12195 # Check textarea content
@@ -134,29 +108,16 @@ def test_q_button_works(self):
134108 wait_for_render (5 )
135109 print ("Cleared textarea" )
136110
137- # Find button index for 'a'
138- a_button_id = None
139- for i in range (100 ):
140- try :
141- text = keyboard .get_button_text (i )
142- if text == "a" :
143- a_button_id = i
144- print (f"Found 'a' button at index { i } " )
145- break
146- except :
147- break
148-
149- self .assertIsNotNone (a_button_id , "Should find 'a' button on keyboard" )
150-
151- # 'a' is at index 11 (second row, first position)
152- a_x = keyboard_area .x1 + button_width // 2
153- a_y = keyboard_area .y1 + button_height + button_height // 2
111+ # Get exact button coordinates using helper function
112+ a_coords = get_keyboard_button_coords (keyboard , "a" )
113+ self .assertIsNotNone (a_coords , "Should find 'a' button on keyboard" )
154114
155- print (f"Estimated 'a' button position: ({ a_x } , { a_y } )" )
115+ print (f"Found 'a' button at index { a_coords ['button_idx' ]} , row { a_coords ['row' ]} , col { a_coords ['col' ]} " )
116+ print (f"Exact 'a' button position: ({ a_coords ['center_x' ]} , { a_coords ['center_y' ]} )" )
156117
157118 # Click the 'a' button
158- print (f"Clicking 'a' button at ({ a_x } , { a_y } )" )
159- simulate_click (a_x , a_y )
119+ print (f"Clicking 'a' button at ({ a_coords [ 'center_x' ] } , { a_coords [ 'center_y' ] } )" )
120+ simulate_click (a_coords [ 'center_x' ], a_coords [ 'center_y' ] )
160121 wait_for_render (10 )
161122
162123 # Check textarea content
0 commit comments