|
| 1 | +"""Notes for the hardcoded values in the `init_pos` dictionary: |
| 2 | +
|
| 3 | +It's impossible to programatically get the initial rendered positions of the nodes, since we would |
| 4 | +need to obtain the node object (in dictionary format), which can be done either by (a) using the |
| 5 | +tapNode callback, which paradoxally requires you to click the node, or (b) by making a complex |
| 6 | +calculation relative to the size of the screen w.r.t largest coordinate in the list of elements. |
| 7 | +But (b) is unreliable, since we do not know how much padding around the graph is required, so it |
| 8 | +will likely be off. |
| 9 | +
|
| 10 | +If there is a need to modify the values in `init_pos`, e.g. if the size of the webdriver screen |
| 11 | +is changed, you can do the following: |
| 12 | + - Run usage-events.py |
| 13 | + - Resize window size to 1280x1000, or preferred size (can be manually done or with selenium) |
| 14 | + - Tap on a node |
| 15 | + - Inside the "Node Object JSON" section, find "renderedPosition" and use the values there |
| 16 | + - Repeat this for all the nodes |
| 17 | +
|
| 18 | +Notice also that there's an offset to Node 3's position. This is because it overlaps with |
| 19 | +Node 6, so clicking on Node 3 will erroneously show that you clicked Node 6. Therefore, adding an |
| 20 | +offset to the y-axis will ensure that the correct node is clicked. |
| 21 | +""" |
1 | 22 | import os |
2 | 23 | import importlib |
3 | 24 | import time |
|
12 | 33 |
|
13 | 34 | class Tests(IntegrationTests): |
14 | 35 | def test_interactions(self): |
| 36 | + # VARIABLES |
| 37 | + drag_error = "Unable to drag Cytoscape nodes properly" |
| 38 | + click_error = "Unable to click Cytoscape nodes properly" |
| 39 | + mouseover_error = "Unable to mouseover Cytoscape nodes properly" |
| 40 | + |
| 41 | + # View module docstring for more information about initial positions |
| 42 | + init_pos = { |
| 43 | + 'Node 1': (80.94611044209678, 333.54879281525285), |
| 44 | + 'Node 2': (375.64032747402433, 628.2430098471805), |
| 45 | + 'Node 3': (277.40892179671516, 514.2945792615018 - 20), |
| 46 | + 'Node 4': (768.5659501832611, 333.54879281525285), |
| 47 | + 'Node 5': (473.8717331513335, 431.780198492562), |
| 48 | + 'Node 6': (277.40892179671516, 530.0116041698712) |
| 49 | + } |
| 50 | + init_x, init_y = init_pos['Node 1'] |
| 51 | + |
| 52 | + # Initialize the apps |
15 | 53 | app = importlib.import_module('usage-events').app |
16 | 54 | self.startServer(app) |
17 | 55 | WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.ID, "cytoscape"))) |
18 | 56 |
|
19 | 57 | actions = ActionChains(self.driver) |
20 | 58 |
|
| 59 | + # FUNCTIONS |
21 | 60 | def save_screenshot(dir_name, name): |
22 | 61 | directory_path = os.path.join( |
23 | 62 | os.path.dirname(__file__), |
@@ -106,23 +145,10 @@ def perform_mouseover(x, y, elem, dir_name='interactions'): |
106 | 145 |
|
107 | 146 | return mouseover_label |
108 | 147 |
|
109 | | - drag_error = "Unable to drag Cytoscape nodes properly" |
110 | | - click_error = "Unable to click Cytoscape nodes properly" |
111 | | - mouseover_error = "Unable to mouseover Cytoscape nodes properly" |
112 | | - |
113 | | - init_pos = { |
114 | | - 'Node 1': (80.94611044209678, 333.54879281525285), |
115 | | - 'Node 2': (375.64032747402433, 628.2430098471805), |
116 | | - 'Node 3': (277.40892179671516, 514.2945792615018 - 20), |
117 | | - 'Node 4': (768.5659501832611, 333.54879281525285), |
118 | | - 'Node 5': (473.8717331513335, 431.780198492562), |
119 | | - 'Node 6': (277.40892179671516, 530.0116041698712) |
120 | | - } |
121 | | - init_x, init_y = init_pos['Node 1'] |
122 | 148 | # Select the JSON output element |
123 | 149 | elem_tap = self.driver.find_element_by_css_selector('pre#tap-node-json-output') |
124 | 150 |
|
125 | | - # # Test dragging the nodes around |
| 151 | + # Test dragging the nodes around |
126 | 152 | offset_x, offset_y = perform_dragging(init_x, init_y, 0, 0, elem_tap) |
127 | 153 | init_x += offset_x |
128 | 154 | init_y += offset_y |
|
0 commit comments