88from selenium .webdriver .support import expected_conditions as EC
99from selenium .webdriver .common .by import By
1010
11+
1112def find_hp_question (selenium_utils , div_id ):
1213 selenium_utils .wait_until_ready (div_id )
1314 return selenium_utils .driver .find_element (By .ID , div_id )
1415
16+
1517def click_control (hp_question , button_name ):
1618 css = '.btn-success.run-button' if button_name == 'Run' else '.btn-warning.run-button'
1719 btn = hp_question .find_element (By .CSS_SELECTOR , css )
1820 btn .click ()
1921
22+
2023"""
2124Test Block Based feedback is correct:
22251-1. Click on three blocks to form a solution that does not have enough blocks
@@ -30,9 +33,11 @@ def click_control(hp_question, button_name):
30334-2. Form a correct solution
31344-3. Click on run button to check the result is hinting completed in one attempt
3235"""
36+
37+
3338def test_run_block (selenium_utils_get ):
3439 div_id = "test_hparsons_block_1"
35- hp_question = find_hp_question (selenium_utils_get , div_id )
40+ hp_question = find_hp_question (selenium_utils_get , div_id )
3641 hp = hp_question .find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
3742 drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
3843 drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
@@ -71,6 +76,8 @@ def test_run_block(selenium_utils_get):
7176 drag_area .find_element (By .CSS_SELECTOR , '.parsons-block' ).click ()
7277 # 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
7378 run_btn .click ()
79+ selenium_utils_get .wait .until (
80+ EC .text_to_be_present_in_element ((By .CLASS_NAME , "alert" ), "It" ))
7481 feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
7582 assert 'It took you 3 tries to solve this.' in feedback_area .text
7683 # 3-3. Check the run button is disabled
@@ -87,19 +94,22 @@ def test_run_block(selenium_utils_get):
8794 # 4-3. Click on run button to check the result is hinting completed in one attempt
8895 run_btn .click ()
8996 feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
90- assert 'It took you only one try to solve this.' in feedback_area .text
97+ assert 'Perfect' in feedback_area .text
98+
9199
92-
93100'''
94101Test if the blocks are properly randomized.
951021. Assert the sequence of the blocks is not the same as set in .rst file.
96103'''
104+
105+
97106def test_randomize_block (selenium_utils_get ):
98107 div_id = "test_hparsons_sql_1"
99- hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
100- original_sequence = ['SELECT' ,'*' ,'FROM' ,'test' ]
108+ hp = find_hp_question (selenium_utils_get , div_id ).find_element (
109+ By .CSS_SELECTOR , 'horizontal-parsons' )
110+ original_sequence = ['SELECT' , '*' , 'FROM' , 'test' ]
101111 randomized_sequence = []
102- for block in hp .find_element (By .CSS_SELECTOR ,'.drag-area' ).find_elements (By .CSS_SELECTOR , '.parsons-block' ):
112+ for block in hp .find_element (By .CSS_SELECTOR , '.drag-area' ).find_elements (By .CSS_SELECTOR , '.parsons-block' ):
103113 randomized_sequence .append (block .text )
104114 assert len (original_sequence ) == len (randomized_sequence )
105115 is_same_order = True
@@ -108,7 +118,7 @@ def test_randomize_block(selenium_utils_get):
108118 is_same_order = False
109119 break
110120 assert not is_same_order
111-
121+
112122
113123"""
114124Test adding and removing blocks by clicking in non-duplicating blocks
@@ -119,9 +129,12 @@ def test_randomize_block(selenium_utils_get):
1191291. Click on the first block and make sure it is copied to the bottom
1201302. Click on the first block in the bottom and make sure it disappears
121131"""
132+
133+
122134def test_add_and_remove_blocks (selenium_utils_get ):
123135 div_id = "test_hparsons_sql_1"
124- hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
136+ hp = find_hp_question (selenium_utils_get , div_id ).find_element (
137+ By .CSS_SELECTOR , 'horizontal-parsons' )
125138 drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
126139 drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
127140
@@ -130,7 +143,7 @@ def test_add_and_remove_blocks(selenium_utils_get):
130143 block1 .click ()
131144 assert block1 not in drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
132145 assert block1 == drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[- 1 ]
133-
146+
134147 # 2. Click on the moved block and make sure it is returned to the top
135148 # block2 and block1 are the same object
136149 block2 = drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[0 ]
@@ -140,16 +153,18 @@ def test_add_and_remove_blocks(selenium_utils_get):
140153
141154 # For reusable blocks
142155 div_id = "test_hparsons_sql_2"
143- hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
156+ hp = find_hp_question (selenium_utils_get , div_id ).find_element (
157+ By .CSS_SELECTOR , 'horizontal-parsons' )
144158 drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
145159 drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
146160
147161 # 1. Click on the first block and make sure it is copied to the bottom
148162 block1 = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[0 ]
149163 block1 .click ()
150164 assert len (drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )) == 4
151- assert block1 .text == drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[- 1 ].text
152-
165+ assert block1 .text == drop_area .find_elements (
166+ By .CSS_SELECTOR , '.parsons-block' )[- 1 ].text
167+
153168 # 2. Click on the moved block and make sure it is removed
154169 block2 = drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[0 ]
155170 block2 .click ()
@@ -162,10 +177,12 @@ def test_add_and_remove_blocks(selenium_utils_get):
1621771. Click on each of the four blocks in second problem to form a solution
1631782. Click on run button to run code and check the result
164179"""
180+
181+
165182def test_run_SQL (selenium_utils_get ):
166183 # For reusable blocks
167184 div_id = "test_hparsons_sql_2"
168- hp_question = find_hp_question (selenium_utils_get , div_id )
185+ hp_question = find_hp_question (selenium_utils_get , div_id )
169186 time .sleep (2 )
170187 hp = hp_question .find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
171188 drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
@@ -175,12 +192,12 @@ def test_run_SQL(selenium_utils_get):
175192 blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
176193 for block in blocks :
177194 block .click ()
178-
195+
179196 # 2. Click on run button to run code and check the result
180197 click_control (hp_question , 'Run' )
181- selenium_utils_get .wait .until (EC .text_to_be_present_in_element ((By .ID , f"{ div_id } _stdout" ), "You" ))
198+ selenium_utils_get .wait .until (
199+ EC .text_to_be_present_in_element ((By .ID , f"{ div_id } _stdout" ), "You" ))
182200 res = selenium_utils_get .driver .find_element (By .ID , f"{ div_id } _sql_out" )
183201 assert res
184202 out = selenium_utils_get .driver .find_element (By .ID , f"{ div_id } _stdout" )
185203 assert "You passed 2 out of 3 tests" in out .text
186-
0 commit comments