@@ -17,6 +17,79 @@ def click_control(hp_question, button_name):
1717 btn = hp_question .find_element (By .CSS_SELECTOR , css )
1818 btn .click ()
1919
20+ """
21+ Test Block Based feedback is correct:
22+ 1-1. Click on three blocks to form a solution that does not have enough blocks
23+ 1-2. Click on run button to check the result is hinting missing blocks
24+ 2-1. Click on more blocks to form an incorrect solution
25+ 2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
26+ 3-1. Click to change to the correct answer
27+ 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
28+ 3-3. Check the run button is disabled
29+ 4-1. Click on reset button
30+ 4-2. Form a correct solution
31+ 4-3. Click on run button to check the result is hinting completed in one attempt
32+ """
33+ def test_run_block (selenium_utils_get ):
34+ div_id = "test_hparsons_block_1"
35+ hp_question = find_hp_question (selenium_utils_get , div_id )
36+ hp = hp_question .find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
37+ drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
38+ drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
39+ run_btn = hp_question .find_elements (By .TAG_NAME , 'button' )[0 ]
40+ reset_btn = hp_question .find_elements (By .TAG_NAME , 'button' )[1 ]
41+
42+ time .sleep (5 )
43+ # 1-1. Click on three blocks to form a solution that does not have enough blocks
44+ for code_piece in ['SELECT' , '*' , 'test' ]:
45+ blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
46+ for block in blocks :
47+ if block .text == code_piece :
48+ time .sleep (1 )
49+ block .click ()
50+ break
51+ # 1-2. Click on run button to check the result is hinting missing blocks
52+ run_btn .click ()
53+ feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
54+ assert 'Your program is too short.' in feedback_area .text
55+
56+ # 2-1. Click on more blocks to form an incorrect solution
57+ block = drag_area .find_element (By .CSS_SELECTOR , '.parsons-block' )
58+ block .click ()
59+ # 2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
60+ run_btn .click ()
61+ time .sleep (1 )
62+ feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
63+ assert 'Highlighted blocks in your program are wrong or are in the wrong order.' in feedback_area .text
64+ highlighted_blocks = []
65+ for block in drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block.incorrectPosition' ):
66+ highlighted_blocks .append (block .text )
67+ assert set (highlighted_blocks ) == set (['FROM' ])
68+
69+ # 3-1. Click to change to the correct answer
70+ drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[2 ].click ()
71+ drag_area .find_element (By .CSS_SELECTOR , '.parsons-block' ).click ()
72+ # 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
73+ run_btn .click ()
74+ feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
75+ assert 'It took you 3 tries to solve this.' in feedback_area .text
76+ # 3-3. Check the run button is disabled
77+ assert run_btn .get_attribute ('disabled' ) == 'true'
78+
79+ # 4-1. Click on reset button
80+ reset_btn .click ()
81+ # 4-2. Form a correct solution
82+ for code_piece in ['SELECT' , '*' , 'FROM' , 'test' ]:
83+ blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
84+ for block in blocks :
85+ if block .text == code_piece :
86+ block .click ()
87+ # 4-3. Click on run button to check the result is hinting completed in one attempt
88+ run_btn .click ()
89+ 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
91+
92+
2093'''
2194Test if the blocks are properly randomized.
22951. Assert the sequence of the blocks is not the same as set in .rst file.
@@ -26,7 +99,7 @@ def test_randomize_block(selenium_utils_get):
2699 hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
27100 original_sequence = ['SELECT' ,'*' ,'FROM' ,'test' ]
28101 randomized_sequence = []
29- for block in hp .shadow_root . find_element (By .CSS_SELECTOR ,'.drag-area' ).find_elements (By .CSS_SELECTOR , '.parsons-block' ):
102+ for block in hp .find_element (By .CSS_SELECTOR ,'.drag-area' ).find_elements (By .CSS_SELECTOR , '.parsons-block' ):
30103 randomized_sequence .append (block .text )
31104 assert len (original_sequence ) == len (randomized_sequence )
32105 is_same_order = True
@@ -49,8 +122,8 @@ def test_randomize_block(selenium_utils_get):
49122def test_add_and_remove_blocks (selenium_utils_get ):
50123 div_id = "test_hparsons_sql_1"
51124 hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
52- drag_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drag-area' )
53- drop_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drop-area' )
125+ drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
126+ drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
54127
55128 # 1. Click on the first block and make sure it is added to the bottom
56129 block1 = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[0 ]
@@ -68,8 +141,8 @@ def test_add_and_remove_blocks(selenium_utils_get):
68141 # For reusable blocks
69142 div_id = "test_hparsons_sql_2"
70143 hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
71- drag_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drag-area' )
72- drop_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drop-area' )
144+ drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
145+ drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
73146
74147 # 1. Click on the first block and make sure it is copied to the bottom
75148 block1 = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[0 ]
@@ -95,8 +168,8 @@ def test_run_SQL(selenium_utils_get):
95168 hp_question = find_hp_question (selenium_utils_get , div_id )
96169 time .sleep (2 )
97170 hp = hp_question .find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
98- drag_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drag-area' )
99- drop_area = hp .shadow_root . find_element (By .CSS_SELECTOR , '.drop-area' )
171+ drag_area = hp .find_element (By .CSS_SELECTOR , '.drag-area' )
172+ drop_area = hp .find_element (By .CSS_SELECTOR , '.drop-area' )
100173
101174 # 1. Click on each of the four blocks in second problem to form a solution
102175 blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
@@ -111,73 +184,3 @@ def test_run_SQL(selenium_utils_get):
111184 out = selenium_utils_get .driver .find_element (By .ID , f"{ div_id } _stdout" )
112185 assert "You passed 2 out of 3 tests" in out .text
113186
114-
115- """
116- Test Block Based feedback is correct:
117- 1-1. Click on three blocks to form a solution that does not have enough blocks
118- 1-2. Click on run button to check the result is hinting missing blocks
119- 2-1. Click on more blocks to form an incorrect solution
120- 2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
121- 3-1. Click to change to the correct answer
122- 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
123- 3-3. Check the run button is disabled
124- 4-1. Click on reset button
125- 4-2. Form a correct solution
126- 4-3. Click on run button to check the result is hinting completed in one attempt
127- """
128- def test_run_block (selenium_utils_get ):
129- div_id = "test_hparsons_block_1"
130- hp_question = find_hp_question (selenium_utils_get , div_id )
131- hp = hp_question .find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
132- drag_area = hp .shadow_root .find_element (By .CSS_SELECTOR , '.drag-area' )
133- drop_area = hp .shadow_root .find_element (By .CSS_SELECTOR , '.drop-area' )
134- run_btn = hp_question .find_elements (By .TAG_NAME , 'button' )[0 ]
135- reset_btn = hp_question .find_elements (By .TAG_NAME , 'button' )[1 ]
136-
137- # 1-1. Click on three blocks to form a solution that does not have enough blocks
138- for code_piece in ['SELECT' , '*' , 'test' ]:
139- blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
140- for block in blocks :
141- if block .text == code_piece :
142- block .click ()
143- # 1-2. Click on run button to check the result is hinting missing blocks
144- run_btn .click ()
145- feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
146- assert 'Your program is too short.' in feedback_area .text
147-
148- # 2-1. Click on more blocks to form an incorrect solution
149- block = drag_area .find_element (By .CSS_SELECTOR , '.parsons-block' )
150- block .click ()
151- # 2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
152- run_btn .click ()
153- time .sleep (1 )
154- feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
155- assert 'Highlighted blocks in your program are wrong or are in the wrong order.' in feedback_area .text
156- highlighted_blocks = []
157- for block in drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block.incorrectPosition' ):
158- highlighted_blocks .append (block .text )
159- assert set (highlighted_blocks ) == set (['FROM' ])
160-
161- # 3-1. Click to change to the correct answer
162- drop_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )[2 ].click ()
163- drag_area .find_element (By .CSS_SELECTOR , '.parsons-block' ).click ()
164- # 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
165- run_btn .click ()
166- feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
167- assert 'It took you 3 tries to solve this.' in feedback_area .text
168- # 3-3. Check the run button is disabled
169- assert run_btn .get_attribute ('disabled' ) == 'true'
170-
171- # 4-1. Click on reset button
172- reset_btn .click ()
173- # 4-2. Form a correct solution
174- for code_piece in ['SELECT' , '*' , 'FROM' , 'test' ]:
175- blocks = drag_area .find_elements (By .CSS_SELECTOR , '.parsons-block' )
176- for block in blocks :
177- if block .text == code_piece :
178- block .click ()
179- # 4-3. Click on run button to check the result is hinting completed in one attempt
180- run_btn .click ()
181- feedback_area = hp_question .find_element (By .CLASS_NAME , 'alert' )
182- assert 'It took you only one try to solve this.' in feedback_area .text
183-
0 commit comments