44from selenium .webdriver import ActionChains
55from selenium .webdriver .support import expected_conditions as EC
66from selenium .webdriver .common .by import By
7- from selenium .common .exceptions import (
8- ElementClickInterceptedException ,
9- )
107
118
129def find_ac (selenium_utils , div_id ):
1310 selenium_utils .wait_until_ready (div_id )
1411 return selenium_utils .driver .find_element_by_id (div_id )
1512
1613
17- def click_run (ac_selenium_element ):
14+ def click_run (selenium_utils , ac_selenium_element ):
15+ # The run button can sometimes be scrolled to the top of the screen, where it's hidden by the navigation bar. In this case, we can't click it, since Selenium will complain ``Message: element click intercepted: Element <button class="btn btn-success run-button" type="button">...</button> is not clickable at point (460, 17). Other element would receive the click: <div class="navbar-collapse collapse navbar-ex1-collapse">...</div>``. To avoid this, always scroll to the top of the document, guaranteeing that the navbar won't be hiding the run button.
16+ selenium_utils .driver .execute_script ("window.scrollTo(0, 0);" )
1817 rb = ac_selenium_element .find_element_by_class_name ("run-button" )
1918 rb .click ()
2019
@@ -29,7 +28,7 @@ def test_hello(selenium_utils_get):
2928 """
3029 div_id = "test_activecode_2"
3130 t1 = find_ac (selenium_utils_get , div_id )
32- click_run (t1 )
31+ click_run (selenium_utils_get , t1 )
3332 selenium_utils_get .wait .until (
3433 EC .text_to_be_present_in_element ((By .ID , f"{ div_id } _stdout" ), "Hello World" ),
3534 message = "Did not find expected text" ,
@@ -47,7 +46,7 @@ def test_hidden(selenium_utils_get):
4746 :return:
4847 """
4948 t1 = find_ac (selenium_utils_get , "testprefixcode" )
50- click_run (t1 )
49+ click_run (selenium_utils_get , t1 )
5150 selenium_utils_get .wait .until (
5251 EC .text_to_be_present_in_element (
5352 (By .ID , "testprefixcode_stdout" ), "My Code"
@@ -68,39 +67,25 @@ def test_history(selenium_utils_get):
6867 """
6968 div_id = "test_activecode_2"
7069 t1 = find_ac (selenium_utils_get , div_id )
71- time .sleep (2 )
72- rb = t1 .find_element_by_class_name ("run-button" )
73- rb .click ()
70+ click_run (selenium_utils_get , t1 )
7471 time .sleep (2 )
7572
7673 ta = t1 .find_element_by_class_name ("cm-s-default" )
7774 assert ta
7875 selenium_utils_get .driver .execute_script (
79- f"""window.edList['{ div_id } '].editor.setValue("print('GoodBye ')")"""
76+ f"""window.edList['{ div_id } '].editor.setValue("print('Goodbye ')")"""
8077 )
81- selenium_utils_get .wait .until (EC .element_to_be_clickable ((By .CLASS_NAME , "run-button" )))
82- try :
83- rb .click ()
84- except ElementClickInterceptedException :
85- interceptor = selenium_utils_get .driver .find_element_by_class_name ("navbar-collapse" )
86- selenium_utils_get .driver .executed_script (
87- """
88- var el = arguments[0];
89- el.parentNode.removeChild(el);
90- """ ,
91- interceptor ,
92- )
93- rb .click ()
94-
78+ click_run (selenium_utils_get , t1 )
9579 time .sleep (2 )
9680 output = t1 .find_element_by_class_name ("ac_output" )
97- assert output .text .strip () == "GoodBye "
81+ assert output .text .strip () == "Goodbye "
9882 move = ActionChains (selenium_utils_get .driver )
9983 slider = t1 .find_element_by_class_name ("ui-slider" )
10084 width = slider .size ["width" ]
10185 slider = t1 .find_element_by_class_name ("ui-slider-handle" )
10286 move .click_and_hold (slider ).move_by_offset (- width , 0 ).release ().perform ()
103- rb .click ()
87+ click_run (selenium_utils_get , t1 )
88+ time .sleep (2 )
10489 output = t1 .find_element_by_class_name ("ac_output" )
10590 assert output .text .strip () == "Hello World"
10691
@@ -111,7 +96,7 @@ def test_livecode_datafile(selenium_utils_get):
11196 Code is dependent on supplementary file
11297 """
11398 t2 = find_ac (selenium_utils_get , "test_activecode_3" )
114- click_run (t2 )
99+ click_run (selenium_utils_get , t2 )
115100 output = t2 .find_element_by_class_name ("ac_output" )
116101
117102 count = 0
@@ -135,7 +120,7 @@ def selenium_utils_progress(selenium_utils):
135120
136121def test_activity_count (selenium_utils_progress ):
137122 t2 = find_ac (selenium_utils_progress , "test_activecode_5" )
138- click_run (t2 )
123+ click_run (selenium_utils_progress , t2 )
139124 pb = selenium_utils_progress .driver .find_element_by_id ("subchapterprogress" )
140125 assert pb
141126 # Wait for the JS to run. Increase this delay if the next assertion fails.
@@ -146,15 +131,15 @@ def test_activity_count(selenium_utils_progress):
146131 # expect only 1 because the page isn't included when not using services
147132 assert 2 == int (possible )
148133 # count should not increment after a second click
149- click_run (t2 )
134+ click_run (selenium_utils_progress , t2 )
150135 total = selenium_utils_progress .driver .find_element_by_id ("scprogresstotal" ).text .strip ()
151136 assert 2 == int (total )
152137
153138
154139def test_sql_activecode (selenium_utils_get ):
155140 div_id = "test_activecode_6"
156141 t2 = find_ac (selenium_utils_get , div_id )
157- click_run (t2 )
142+ click_run (selenium_utils_get , t2 )
158143 selenium_utils_get .wait .until (EC .text_to_be_present_in_element ((By .ID , f"{ div_id } _stdout" ), "You" ))
159144 res = selenium_utils_get .driver .find_element_by_id (f"{ div_id } _sql_out" )
160145 assert res
@@ -163,7 +148,7 @@ def test_sql_activecode(selenium_utils_get):
163148
164149 div_id = "test_activecode_7"
165150 t2 = find_ac (selenium_utils_get , div_id )
166- click_run (t2 )
151+ click_run (selenium_utils_get , t2 )
167152 out = selenium_utils_get .driver .find_element_by_id (f"{ div_id } _stdout" )
168153 assert "" == out .text .strip ()
169154
@@ -176,7 +161,7 @@ def selenium_utils_sf(selenium_utils):
176161
177162def test_readfiles (selenium_utils_sf ):
178163 t2 = find_ac (selenium_utils_sf , "ac9_13_1" )
179- click_run (t2 )
164+ click_run (selenium_utils_sf , t2 )
180165 selenium_utils_sf .wait .until (
181166 EC .text_to_be_present_in_element ((By .ID , "ac9_13_1_stdout" ), "Lind" )
182167 )
@@ -186,7 +171,7 @@ def test_readfiles(selenium_utils_sf):
186171
187172def test_altair (selenium_utils_sf ):
188173 t2 = find_ac (selenium_utils_sf , "alt_kiva_bar1" )
189- click_run (t2 )
174+ click_run (selenium_utils_sf , t2 )
190175 out = t2 .find_element_by_id ("alt_kiva_bar1_stdout" )
191176 selenium_utils_sf .wait .until (
192177 EC .text_to_be_present_in_element (
@@ -200,7 +185,7 @@ def test_altair(selenium_utils_sf):
200185
201186def test_image (selenium_utils_sf ):
202187 t2 = find_ac (selenium_utils_sf , "ac14_7_2" )
203- click_run (t2 )
188+ click_run (selenium_utils_sf , t2 )
204189 selenium_utils_sf .wait .until (
205190 EC .text_to_be_present_in_element ((By .ID , "ac14_7_2_stdout" ), "400" )
206191 )
0 commit comments