Skip to content

Commit 586278b

Browse files
author
Xing Han Lu
committed
Create test_callbacks.py
1 parent 1dc590a commit 586278b

File tree

1 file changed

+332
-0
lines changed

1 file changed

+332
-0
lines changed

tests/test_callbacks.py

Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
import os
2+
import importlib
3+
4+
from .IntegrationTests import IntegrationTests
5+
from selenium.webdriver.common.by import By
6+
from selenium.webdriver.support.ui import WebDriverWait
7+
from selenium.webdriver.support import expected_conditions as EC
8+
from selenium.webdriver.common.keys import Keys
9+
10+
11+
class Tests(IntegrationTests):
12+
def test_callbacks(self):
13+
app = importlib.import_module('usage-advanced').app
14+
self.startServer(app)
15+
16+
WebDriverWait(self.driver, 20).until(
17+
EC.presence_of_element_located((By.ID, "cytoscape"))
18+
)
19+
20+
def create_input_and_save(css_selector,
21+
dir_name,
22+
options,
23+
prefix=None,
24+
name_map=None,
25+
save=True):
26+
elem = self.driver.find_element_by_css_selector(css_selector)
27+
28+
directory_path = os.path.join(
29+
os.path.dirname(__file__),
30+
'screenshots',
31+
dir_name
32+
)
33+
34+
# Create directory if it doesn't already exist
35+
if not os.path.exists(directory_path):
36+
os.makedirs(directory_path)
37+
38+
if prefix and not name_map:
39+
name_map = {
40+
option: prefix + option
41+
for option in options
42+
}
43+
44+
elif not name_map:
45+
name_map = {}
46+
47+
for option in options:
48+
elem.send_keys(Keys.CONTROL + "a")
49+
elem.send_keys(option)
50+
elem.send_keys(Keys.RETURN)
51+
52+
if save:
53+
# If the name map doesn't contain a custom name for the option,
54+
# we default to the value of the option to name the saved
55+
# screenshot
56+
name = name_map.get(option, option)
57+
name = name.replace('(', '_').replace(')', '').replace(',', '_')
58+
name = name.replace('#', '_hex_').replace(' ', '')
59+
60+
WebDriverWait(self.driver, 20).until(
61+
EC.presence_of_element_located((By.ID, "cytoscape"))
62+
)
63+
64+
path = os.path.join(
65+
os.path.dirname(__file__),
66+
'screenshots',
67+
dir_name,
68+
name + '.png'
69+
)
70+
71+
self.driver.save_screenshot(path)
72+
73+
def click_button_and_save(name_to_xpaths, dir_name, save=True):
74+
for name, xpath in name_to_xpaths.items():
75+
button = self.driver.find_element(By.XPATH, xpath)
76+
button.click()
77+
78+
if save:
79+
WebDriverWait(self.driver, 20).until(
80+
EC.presence_of_element_located((By.ID, "cytoscape"))
81+
)
82+
83+
path = os.path.join(
84+
os.path.dirname(__file__),
85+
'screenshots',
86+
dir_name,
87+
name + '.png'
88+
)
89+
90+
self.driver.save_screenshot(path)
91+
92+
create_input_and_save(
93+
css_selector='input#dropdown-select-element-list',
94+
dir_name='elements',
95+
options=['Basic', 'Compound', 'Gene', 'Wineandcheese']
96+
)
97+
98+
create_input_and_save(
99+
css_selector='input#dropdown-layout',
100+
dir_name='layouts',
101+
options=[
102+
'Preset',
103+
'Grid',
104+
'Circle',
105+
'Concentric',
106+
'Breadthfirst',
107+
'Cose'
108+
]
109+
)
110+
111+
# Reset the input to what it was at the beginning
112+
create_input_and_save(
113+
css_selector='input#dropdown-select-element-list',
114+
dir_name='elements',
115+
options=['Basic'],
116+
save=False
117+
)
118+
create_input_and_save(
119+
css_selector='input#dropdown-layout',
120+
dir_name='layouts',
121+
options=['Circle'],
122+
save=False
123+
)
124+
125+
# Input Different types of Node Content
126+
create_input_and_save(
127+
css_selector='input#input-node-content',
128+
dir_name='style',
129+
options=[
130+
'Hello',
131+
'data(id)'
132+
],
133+
name_map={
134+
'Hello': 'NodeDisplayContentStatic',
135+
'data(id)': 'NodeDisplayID'
136+
}
137+
)
138+
139+
# Input Different node widths
140+
create_input_and_save(
141+
css_selector='input#input-node-width',
142+
dir_name='style',
143+
options=[
144+
'30',
145+
'50'
146+
],
147+
prefix='NodeWidth'
148+
)
149+
150+
# Input Different node heights
151+
create_input_and_save(
152+
css_selector='input#input-node-height',
153+
dir_name='style',
154+
options=[
155+
'40',
156+
'60'
157+
],
158+
prefix='NodeHeight'
159+
)
160+
161+
# Input different node shapes
162+
create_input_and_save(
163+
css_selector='input#dropdown-node-shape',
164+
dir_name='style',
165+
options=[
166+
'Triangle',
167+
'Rectangle',
168+
'Roundrectangle',
169+
'Barrel',
170+
'Diamond',
171+
'Pentagon',
172+
'Star',
173+
'Tag',
174+
'Vee',
175+
'Ellipse'
176+
],
177+
prefix='NodeShape'
178+
)
179+
180+
create_input_and_save(
181+
css_selector='input#input-node-color',
182+
dir_name='style',
183+
options=[
184+
'pink',
185+
'sky blue',
186+
'rgb(186,44,162)',
187+
'#def229'
188+
],
189+
prefix='NodeColor'
190+
)
191+
192+
create_input_and_save(
193+
css_selector='input#input-node-border-width',
194+
dir_name='style',
195+
options=['2'],
196+
save=False
197+
)
198+
199+
create_input_and_save(
200+
css_selector='input#input-node-border-color',
201+
dir_name='style',
202+
options=[
203+
'pink',
204+
'sky blue',
205+
'rgb(186,44,162)',
206+
'#def229'
207+
],
208+
prefix='BorderColor'
209+
)
210+
211+
create_input_and_save(
212+
css_selector='input#input-node-border-width',
213+
dir_name='style',
214+
options=['5', '2'],
215+
prefix='NodeBorderWidth'
216+
)
217+
218+
create_input_and_save(
219+
css_selector='input#dropdown-node-border-style',
220+
dir_name='style',
221+
options=[
222+
'Dashed',
223+
'Dotted',
224+
'Double',
225+
'Solid',
226+
],
227+
prefix='NodeBorderStyle'
228+
)
229+
230+
create_input_and_save(
231+
css_selector='input#input-node-padding',
232+
dir_name='style',
233+
options=['5px'],
234+
prefix='NodePadding'
235+
)
236+
237+
create_input_and_save(
238+
css_selector='input#dropdown-node-padding-relative-to',
239+
dir_name='style',
240+
options=['Width', 'Height', 'Average', 'Min', 'Max'],
241+
prefix='NodePaddingRelativeTo'
242+
)
243+
244+
create_input_and_save(
245+
css_selector='input#input-edge-line-width',
246+
dir_name='style',
247+
options=['10', '1', '3'],
248+
prefix='LineWidth'
249+
)
250+
251+
create_input_and_save(
252+
css_selector='input#dropdown-edge-curve-style',
253+
dir_name='style',
254+
options=['Haystack', 'Segments', 'Unbundled-bezier', 'Bezier'],
255+
prefix='EdgeCurveStyle'
256+
)
257+
258+
create_input_and_save(
259+
css_selector='input#input-edge-line-color',
260+
dir_name='style',
261+
options=[
262+
'pink',
263+
'sky blue',
264+
'rgb(186,44,162)',
265+
'#def229'
266+
],
267+
prefix='EdgeColor'
268+
)
269+
270+
# Modify Edge Styles
271+
click_button_and_save(
272+
name_to_xpaths={
273+
'EdgeStyleSolid': '//*[@id="radio-edge-line-style"]/label[1]',
274+
'EdgeStyleDotted': '//*[@id="radio-edge-line-style"]/label[2]',
275+
'EdgeStyleDashed': '//*[@id="radio-edge-line-style"]/label[3]',
276+
},
277+
dir_name='style'
278+
)
279+
280+
# Set "Use Edge Arrow" to "Yes"
281+
click_button_and_save(
282+
name_to_xpaths={
283+
'EdgeArrow': '//*[@id="radio-use-edge-arrow"]/label[1]'},
284+
dir_name='style',
285+
save=False
286+
)
287+
288+
create_input_and_save(
289+
css_selector='input#dropdown-source-arrow-shape',
290+
dir_name='style',
291+
options=[
292+
'Circle',
293+
'Vee',
294+
'Tee',
295+
'Diamond',
296+
'Triangle'
297+
],
298+
prefix='EdgeArrowShape'
299+
)
300+
301+
create_input_and_save(
302+
css_selector='input#input-source-arrow-color',
303+
dir_name='style',
304+
options=[
305+
'pink',
306+
'sky blue',
307+
'rgb(186,44,162)',
308+
'#def229'
309+
],
310+
prefix='EdgeArrowColor'
311+
)
312+
313+
click_button_and_save(
314+
name_to_xpaths={
315+
'EdgeArrowFilled': ('//*[@id="radio-source-arrow-fill"]/'
316+
'label[1]'),
317+
'EdgeArrowHollow': ('//*[@id="radio-source-arrow-fill"]/'
318+
'label[2]')
319+
},
320+
dir_name='style'
321+
)
322+
323+
create_input_and_save(
324+
css_selector='input#input-arrow-scale',
325+
dir_name='style',
326+
options=[
327+
'3',
328+
'2',
329+
'1'
330+
],
331+
prefix='EdgeArrowScale'
332+
)

0 commit comments

Comments
 (0)