@@ -89,32 +89,20 @@ def upload_icomoon(self, icomoon_json_path: str):
8989 :raises TimeoutException: happens when elements are not found.
9090 """
9191 print ("Uploading icomoon.json file..." )
92- try :
93- self .click_hamburger_input ()
94-
95- # find the file input and enter the file path
96- import_btn = self .driver .find_element (By .XPATH , "(//li[@class='file'])[1]//input" )
97- import_btn .send_keys (icomoon_json_path )
98- except SeleniumTimeoutException as e :
99- print (e .stacktrace )
100- print ("Selenium timed out. Couldn't find import button." )
101- self .close ()
102- raise e
103- except Exception as e :
104- self .close ()
105- raise e
92+ self .click_hamburger_input ()
93+
94+ # find the file input and enter the file path
95+ import_btn = self .driver .find_element (By .XPATH , "(//li[@class='file'])[1]//input" )
96+ import_btn .send_keys (icomoon_json_path )
10697
10798 try :
10899 confirm_btn = WebDriverWait (self .driver , SeleniumRunner .MED_WAIT_IN_SEC ).until (
109100 ec .element_to_be_clickable ((By .XPATH , "//div[@class='overlay']//button[text()='Yes']" ))
110101 )
111102 confirm_btn .click ()
112103 except SeleniumTimeoutException as e :
113- print (e .stacktrace )
114- print ("Cannot find the confirm button when uploading the icomoon.json" ,
115- "Ensure that the icomoon.json is in the correct format for Icomoon.io" ,
116- sep = '\n ' )
117- self .close ()
104+ raise Exception ("Cannot find the confirm button when uploading the icomoon.json" \
105+ "Ensure that the icomoon.json is in the correct format for Icomoon.io" )
118106
119107 print ("JSON file uploaded." )
120108
@@ -126,39 +114,29 @@ def upload_svgs(self, svgs: List[str], screenshot_folder: str=""):
126114 the value is provided, it means the user want to take a screenshot
127115 of each icon.
128116 """
129- try :
130- print ("Uploading SVGs..." )
117+ print ("Uploading SVGs..." )
131118
132- edit_mode_btn = self .driver .find_element_by_css_selector (
133- "div.btnBar button i.icon-edit"
134- )
135- edit_mode_btn .click ()
136-
137- self .click_hamburger_input ()
138-
139- for i in range (len (svgs )):
140- import_btn = self .driver .find_element_by_css_selector (
141- "li.file input[type=file]"
142- )
143- import_btn .send_keys (svgs [i ])
144- print (f"Uploaded { svgs [i ]} " )
145- self .test_for_possible_alert (self .SHORT_WAIT_IN_SEC , "Dismiss" )
146- self .click_on_just_added_icon (screenshot_folder , i )
147-
148- # take a screenshot of the icons that were just added
149- new_icons_path = str (Path (screenshot_folder , "new_icons.png" ).resolve ())
150- self .driver .save_screenshot (new_icons_path );
151-
152- # select all the svgs so that the newly added svg are part of the collection
153- self .click_hamburger_input ()
154- select_all_button = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
155- ec .element_to_be_clickable ((By .XPATH , "//button[text()='Select All']" ))
119+ edit_mode_btn = self .driver .find_element_by_css_selector (
120+ "div.btnBar button i.icon-edit"
121+ )
122+ edit_mode_btn .click ()
123+
124+ self .click_hamburger_input ()
125+
126+ for i in range (len (svgs )):
127+ import_btn = self .driver .find_element_by_css_selector (
128+ "li.file input[type=file]"
156129 )
157- select_all_button .click ()
158- print ("Finished uploading the svgs..." )
159- except Exception as e :
160- self .close ()
161- raise e
130+ import_btn .send_keys (svgs [i ])
131+ print (f"Uploaded { svgs [i ]} " )
132+ self .test_for_possible_alert (self .SHORT_WAIT_IN_SEC , "Dismiss" )
133+ self .click_on_just_added_icon (screenshot_folder , i )
134+
135+ # take a screenshot of the icons that were just added
136+ new_icons_path = str (Path (screenshot_folder , "new_icons.png" ).resolve ())
137+ self .driver .save_screenshot (new_icons_path );
138+
139+ print ("Finished uploading the svgs..." )
162140
163141 def click_hamburger_input (self ):
164142 """
@@ -167,20 +145,16 @@ def click_hamburger_input(self):
167145 input two times before the menu appears.
168146 :return: None.
169147 """
170- try :
171- hamburger_input = self .driver .find_element_by_xpath (
172- "(//i[@class='icon-menu'])[2]"
173- )
148+ hamburger_input = self .driver .find_element_by_xpath (
149+ "(//i[@class='icon-menu'])[2]"
150+ )
174151
175- menu_appear_callback = ec .element_to_be_clickable (
176- (By .CSS_SELECTOR , "h1 ul.menuList2" )
177- )
152+ menu_appear_callback = ec .element_to_be_clickable (
153+ (By .CSS_SELECTOR , "h1 ul.menuList2" )
154+ )
178155
179- while not menu_appear_callback (self .driver ):
180- hamburger_input .click ()
181- except Exception as e :
182- self .close ()
183- raise e
156+ while not menu_appear_callback (self .driver ):
157+ hamburger_input .click ()
184158
185159 def test_for_possible_alert (self , wait_period : float , btn_text : str ):
186160 """
@@ -204,25 +178,21 @@ def click_on_just_added_icon(self, screenshot_folder: str, index: int):
204178 Click on the most recently added icon so we can remove the colors
205179 and take a snapshot if needed.
206180 """
207- try :
208- recently_uploaded_icon = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
209- ec .element_to_be_clickable ((By .XPATH , "//div[@id='set0']//mi-box[1]//div" ))
210- )
211- recently_uploaded_icon .click ()
181+ recently_uploaded_icon = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
182+ ec .element_to_be_clickable ((By .XPATH , "//div[@id='set0']//mi-box[1]//div" ))
183+ )
184+ recently_uploaded_icon .click ()
212185
213- self .remove_color_from_icon ()
186+ self .remove_color_from_icon ()
214187
215- if screenshot_folder :
216- screenshot_path = str (Path (screenshot_folder , f"screenshot_{ index } .png" ).resolve ())
217- self .driver .save_screenshot (screenshot_path )
218- print ("Took screenshot and saved it at " + screenshot_path )
188+ if screenshot_folder :
189+ screenshot_path = str (Path (screenshot_folder , f"screenshot_{ index } .png" ).resolve ())
190+ self .driver .save_screenshot (screenshot_path )
191+ print ("Took screenshot and saved it at " + screenshot_path )
219192
220- close_btn = self .driver \
221- .find_element_by_css_selector ("div.overlayWindow i.icon-close" )
222- close_btn .click ()
223- except Exception as e :
224- self .close ()
225- raise e
193+ close_btn = self .driver \
194+ .find_element_by_css_selector ("div.overlayWindow i.icon-close" )
195+ close_btn .click ()
226196
227197 def remove_color_from_icon (self ):
228198 """
@@ -232,38 +202,45 @@ def remove_color_from_icon(self):
232202 The color removal is also necessary so that the Icomoon-generated
233203 icons fit within one font symbol/ligiature.
234204 """
235- color_tab = WebDriverWait (self .driver , self .SHORT_WAIT_IN_SEC ).until (
236- ec .element_to_be_clickable ((By .CSS_SELECTOR , "div.overlayWindow i.icon-droplet" ))
237- )
238- color_tab .click ()
205+ try :
206+ color_tab = WebDriverWait (self .driver , self .SHORT_WAIT_IN_SEC ).until (
207+ ec .element_to_be_clickable ((By .CSS_SELECTOR , "div.overlayWindow i.icon-droplet" ))
208+ )
209+ color_tab .click ()
239210
240- remove_color_btn = self .driver \
241- .find_element_by_css_selector ("div.overlayWindow i.icon-droplet-cross" )
242- remove_color_btn .click ()
211+ remove_color_btn = self .driver \
212+ .find_element_by_css_selector ("div.overlayWindow i.icon-droplet-cross" )
213+ remove_color_btn .click ()
214+ except SeleniumTimeoutException :
215+ pass # do nothing cause sometimes, the color tab doesn't appear in the site
243216
244217 def download_icomoon_fonts (self , zip_path : Path ):
245218 """
246219 Download the icomoon.zip from icomoon.io.
247220 :param zip_path: the path to the zip file after it's downloaded.
248221 """
249- try :
250- print ("Downloading Font files..." )
251- self .driver .find_element_by_css_selector (
252- "a[href='#/select/font']"
253- ).click ()
254-
255- self .test_for_possible_alert (self .MED_WAIT_IN_SEC , "Continue" )
256- download_btn = WebDriverWait (self .driver , SeleniumRunner .LONG_WAIT_IN_SEC ).until (
257- ec .presence_of_element_located ((By .CSS_SELECTOR , "button.btn4 span" ))
258- )
259- download_btn .click ()
260- if self .wait_for_zip (zip_path ):
261- print ("Font files downloaded." )
262- else :
263- raise TimeoutError (f"Couldn't find { zip_path } after download button was clicked." )
264- except Exception as e :
265- self .close ()
266- raise e
222+ # select all the svgs so that the newly added svg are part of the collection
223+ self .click_hamburger_input ()
224+ select_all_button = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
225+ ec .element_to_be_clickable ((By .XPATH , "//button[text()='Select All']" ))
226+ )
227+ select_all_button .click ()
228+
229+ print ("Downloading Font files..." )
230+ font_tab = self .driver .find_element_by_css_selector (
231+ "a[href='#/select/font']"
232+ )
233+ font_tab .click ()
234+
235+ self .test_for_possible_alert (self .MED_WAIT_IN_SEC , "Continue" )
236+ download_btn = WebDriverWait (self .driver , SeleniumRunner .LONG_WAIT_IN_SEC ).until (
237+ ec .presence_of_element_located ((By .CSS_SELECTOR , "button.btn4 span" ))
238+ )
239+ download_btn .click ()
240+ if self .wait_for_zip (zip_path ):
241+ print ("Font files downloaded." )
242+ else :
243+ raise TimeoutError (f"Couldn't find { zip_path } after download button was clicked." )
267244
268245 def wait_for_zip (self , zip_path : Path ) -> bool :
269246 """
0 commit comments