23
23
import importlib
24
24
import time
25
25
import json
26
- import platform
27
26
28
- from .IntegrationTests import IntegrationTests
29
- from selenium .webdriver .common .by import By
30
- from selenium .webdriver .support .ui import WebDriverWait
31
- from selenium .webdriver .support import expected_conditions as EC
32
27
from selenium .webdriver .common .action_chains import ActionChains
33
28
34
29
35
- class Tests (IntegrationTests ):
36
- @classmethod
37
- def setUpClass (cls ):
38
- super (Tests , cls ).setUpClass ()
39
-
30
+ class Tests :
31
+ def create_app (self , dash_duo ):
40
32
# Initialize the apps
41
33
app = importlib .import_module ('usage-events' ).app
42
- cls .startServer (cls , app )
43
- WebDriverWait (cls .driver , 20 ).until (EC .presence_of_element_located ((By .ID , "cytoscape" )))
44
- cls .actions = ActionChains (cls .driver )
45
- cls .init_pos = {
34
+
35
+ dash_duo .start_server (app )
36
+ dash_duo .wait_for_element_by_id ("cytoscape" , 20 )
37
+
38
+ self .actions = ActionChains (dash_duo .driver )
39
+ self .init_pos = {
46
40
'Node 1' : (59 , 182 ),
47
41
'Node 2' : (222 , 345 ),
48
42
'Node 3' : (168 , 283 - 20 ),
@@ -51,21 +45,6 @@ def setUpClass(cls):
51
45
'Node 6' : (168 , 283 )
52
46
}
53
47
54
- @classmethod
55
- def tearDownClass (cls ):
56
- super (Tests , cls ).tearDownClass ()
57
-
58
- time .sleep (3 )
59
- if platform .system () == 'Windows' :
60
- cls .driver .get ('http://localhost:8050/stop' )
61
- else :
62
- cls .server_process .terminate ()
63
- time .sleep (3 )
64
- cls .driver .quit ()
65
-
66
- def tearDown (self ):
67
- pass
68
-
69
48
def save_screenshot (self , dir_name , name ):
70
49
directory_path = os .path .join (
71
50
os .path .dirname (__file__ ),
@@ -77,7 +56,7 @@ def save_screenshot(self, dir_name, name):
77
56
if not os .path .exists (directory_path ):
78
57
os .makedirs (directory_path )
79
58
80
- self .driver .save_screenshot (os .path .join (
59
+ self .dash_duo . driver .save_screenshot (os .path .join (
81
60
os .path .dirname (__file__ ),
82
61
'screenshots' ,
83
62
dir_name ,
@@ -96,7 +75,7 @@ def perform_dragging(self, x, y, delta_x, delta_y, elem, actions, dir_name='inte
96
75
"""
97
76
actions .reset_actions ()
98
77
actions .move_to_element_with_offset (
99
- self .driver .find_element_by_tag_name ('body' ), x , y
78
+ self .dash_duo . driver .find_element_by_tag_name ('body' ), x , y
100
79
)
101
80
actions .drag_and_drop_by_offset (source = None , xoffset = delta_x , yoffset = delta_y )
102
81
actions .click ()
@@ -127,7 +106,7 @@ def perform_clicking(self, x, y, elem, actions, dir_name='interactions'):
127
106
"""
128
107
actions .reset_actions ()
129
108
actions .move_to_element_with_offset (
130
- self .driver .find_element_by_tag_name ('body' ), x , y
109
+ self .dash_duo . driver .find_element_by_tag_name ('body' ), x , y
131
110
)
132
111
actions .click ()
133
112
actions .perform ()
@@ -142,7 +121,7 @@ def perform_clicking(self, x, y, elem, actions, dir_name='interactions'):
142
121
def perform_mouseover (self , x , y , elem , actions , dir_name = 'interactions' ):
143
122
actions .reset_actions ()
144
123
actions .move_to_element_with_offset (
145
- self .driver .find_element_by_tag_name ('body' ), x - 50 , y
124
+ self .dash_duo . driver .find_element_by_tag_name ('body' ), x - 50 , y
146
125
)
147
126
actions .move_by_offset (50 , 0 )
148
127
actions .perform ()
@@ -154,7 +133,10 @@ def perform_mouseover(self, x, y, elem, actions, dir_name='interactions'):
154
133
155
134
return mouseover_label
156
135
157
- def test_dragging (self ):
136
+ def test_dragging (self , dash_duo ):
137
+ self .dash_duo = dash_duo
138
+ self .create_app (dash_duo )
139
+
158
140
drag_error = "Unable to drag Cytoscape nodes properly"
159
141
160
142
# View module docstring for more information about initial positions
@@ -164,7 +146,7 @@ def test_dragging(self):
164
146
actions = self .actions
165
147
166
148
# Select the JSON output element
167
- elem_tap = self . driver . find_element_by_css_selector ('pre#tap-node-json-output' )
149
+ elem_tap = dash_duo . find_element ('pre#tap-node-json-output' )
168
150
169
151
# Test dragging the nodes around
170
152
offset_x , offset_y = self .perform_dragging (init_x , init_y , 0 , 0 , elem_tap , actions )
@@ -178,33 +160,38 @@ def test_dragging(self):
178
160
assert self .perform_dragging (init_x + 150 , init_y + 150 , - 150 , - 150 , elem_tap , actions ) == \
179
161
(- 150 , - 150 ), drag_error
180
162
181
- def test_clicking (self ):
163
+ def test_clicking (self , dash_duo ):
164
+ self .dash_duo = dash_duo
165
+ self .create_app (dash_duo )
166
+
182
167
click_error = "Unable to click Cytoscape nodes properly"
183
168
actions = self .actions
184
169
185
170
# Select the JSON output element
186
- elem_tap = self . driver . find_element_by_css_selector ('pre#tap-node-json-output' )
171
+ elem_tap = dash_duo . find_element ('pre#tap-node-json-output' )
187
172
188
173
init_pos = self .init_pos
189
174
# Test clicking the nodes
190
175
for i in range (1 , 7 ):
191
176
label = 'Node {}' .format (i )
192
177
assert self .perform_clicking (* init_pos [label ], elem_tap , actions ) == label , click_error
193
178
194
- def test_mouseover (self ):
179
+ def test_mouseover (self , dash_duo ):
180
+ self .dash_duo = dash_duo
181
+ self .create_app (dash_duo )
182
+
195
183
init_pos = self .init_pos
196
184
mouseover_error = "Unable to mouseover Cytoscape nodes properly"
197
185
actions = self .actions
198
186
199
187
# Open the Mouseover JSON tab
200
188
actions .move_to_element (
201
- self . driver . find_element_by_css_selector ('#tabs > div:nth-child(3)' ))
189
+ dash_duo . find_element ('#tabs > div:nth-child(3)' ))
202
190
actions .click ().perform ()
203
191
time .sleep (1 )
204
192
205
193
# Select the JSON output element
206
- elem_mouseover = self .driver .find_element_by_css_selector (
207
- 'pre#mouseover-node-data-json-output' )
194
+ elem_mouseover = dash_duo .find_element ('pre#mouseover-node-data-json-output' )
208
195
209
196
# Test hovering the nodes
210
197
for i in range (1 , 7 ):
0 commit comments