1+ """
2+ Test horizontal Parsons problems directive
3+ """
4+
5+ __author__ = "zihan wu"
6+
7+ import time
8+ from selenium .webdriver import ActionChains
9+ from selenium .webdriver .common .by import By
10+
11+ def find_hp_question (selenium_utils , div_id ):
12+ selenium_utils .wait_until_ready (div_id )
13+ return selenium_utils .driver .find_element (By .ID , div_id )
14+
15+
16+ '''
17+ Test if the blocks are properly randomized.
18+ 1. Assert the sequence of the blocks is not the same as set in .rst file.
19+ '''
20+ def test_randomize_block (selenium_utils_get ):
21+ div_id = "test_hparsons_sql_1"
22+ hp = find_hp_question (selenium_utils_get , div_id ).find_element (By .CSS_SELECTOR , 'horizontal-parsons' )
23+ original_sequence = ['SELECT' ,'*' ,'FROM' ,'test' ]
24+ randomized_sequence = []
25+ for block in hp .shadow_root .find_element (By .CSS_SELECTOR ,'.drag-area' ).find_elements (By .CSS_SELECTOR , '.parsons-block' ):
26+ randomized_sequence .append (block .text )
27+ assert len (original_sequence ) == len (randomized_sequence )
28+ is_same_order = True
29+ for i in range (len (original_sequence )):
30+ if original_sequence [i ] != randomized_sequence [i ]:
31+ is_same_order = False
32+ break
33+ assert not is_same_order
34+
35+
36+ # # Test adding and removing blocks by clicking in non-duplicating blocks
37+ # """
38+ # 1. Click on the first block and make sure it is moved to the bottom
39+ # 2. Click on the first block in the bottom and make sure it is put back
40+ # """
41+ # def test_add_and_remove_blocks(selenium_utils_get):
42+ # div_id = "test_hparsons_sql_1"
43+ # hp = find_hp_question(selenium_utils_get, div_id).find_element(By.CSS_SELECTOR, 'horizontal-parsons')
44+ # drag_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drag-area')
45+ # drop_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drop-area')
46+
47+ # # 1. Click on the first block and make sure it is added to the bottom
48+ # block1 = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
49+ # block1.click()
50+ # assert block1 not in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
51+ # assert block1 == drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
52+
53+
54+ # # 2. Drag the remaining first block and make sure it is added to the bottom
55+ # drag = [x.text for x in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')]
56+ # print(drag)
57+ # block2 = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
58+ # # ActionChains(selenium_utils_get.driver).drag_and_drop(
59+ # # block2, drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
60+ # # ).perform()
61+ # ActionChains(selenium_utils_get.driver).drag_and_drop(
62+ # block2, drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
63+ # ).perform()
64+ # time.sleep(2)
65+
66+ # drag = [x.text for x in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')]
67+ # print(drag)
68+
69+ # # assert block2 not in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
70+ # # assert block2 == drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
71+ # assert block2 in drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
72+
73+ # # 2. Click on the moved block and make sure it is returned to the top
74+ # # block2 and block1 are the same object
75+ # block2 = drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
76+ # block2.click()
77+ # assert block2 not in drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
78+ # assert block2 == drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
0 commit comments