@@ -118,10 +118,13 @@ def upload_icomoon(self, icomoon_json_path: str):
118118
119119 print ("JSON file uploaded." )
120120
121- def upload_svgs (self , svgs : List [str ]):
121+ def upload_svgs (self , svgs : List [str ], screenshot_folder : str = "" ):
122122 """
123123 Upload the SVGs provided in folder_info
124124 :param svgs: a list of svg Paths that we'll upload to icomoon.
125+ :param screenshot_folder: the name of the screenshot_folder. If
126+ the value is provided, it means the user want to take a screenshot
127+ of each icon.
125128 """
126129 try :
127130 print ("Uploading SVGs..." )
@@ -133,17 +136,20 @@ def upload_svgs(self, svgs: List[str]):
133136
134137 self .click_hamburger_input ()
135138
136- for svg in svgs :
139+ for i in range ( len ( svgs )) :
137140 import_btn = self .driver .find_element_by_css_selector (
138141 "li.file input[type=file]"
139142 )
140- import_btn .send_keys (svg )
141- print (f"Uploaded { svg } " )
143+ import_btn .send_keys (svgs [ i ] )
144+ print (f"Uploaded { svgs [ i ] } " )
142145 self .test_for_possible_alert (self .SHORT_WAIT_IN_SEC , "Dismiss" )
143- self .remove_color_from_icon ( )
146+ self .click_on_just_added_icon ( screenshot_folder , i )
144147
145148 # take a screenshot of the icons that were just added
146- self .driver .save_screenshot ("new_icons.png" );
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
147153 self .click_hamburger_input ()
148154 select_all_button = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
149155 ec .element_to_be_clickable ((By .XPATH , "//button[text()='Select All']" ))
@@ -191,45 +197,50 @@ def test_for_possible_alert(self, wait_period: float, btn_text: str):
191197 )
192198 dismiss_btn .click ()
193199 except SeleniumTimeoutException :
194- pass
200+ pass # nothing found => everything is good
195201
196- def remove_color_from_icon (self ):
202+ def click_on_just_added_icon (self , screenshot_folder : str , index : int ):
197203 """
198- Remove the color from the most recent uploaded icon.
199- :return: None .
204+ Click on the most recently added icon so we can remove the colors
205+ and take a snapshot if needed .
200206 """
201207 try :
202208 recently_uploaded_icon = WebDriverWait (self .driver , self .LONG_WAIT_IN_SEC ).until (
203209 ec .element_to_be_clickable ((By .XPATH , "//div[@id='set0']//mi-box[1]//div" ))
204210 )
205211 recently_uploaded_icon .click ()
206- except Exception as e :
207- self .close ()
208- raise e
209212
210- try :
211- color_tab = WebDriverWait (self .driver , self .SHORT_WAIT_IN_SEC ).until (
212- ec .element_to_be_clickable ((By .CSS_SELECTOR , "div.overlayWindow i.icon-droplet" ))
213- )
214- color_tab .click ()
213+ self .remove_color_from_icon ()
215214
216- remove_color_btn = self .driver \
217- .find_element_by_css_selector ("div.overlayWindow i.icon-droplet-cross" )
218- remove_color_btn .click ()
219- except SeleniumTimeoutException :
220- pass
221- except Exception as e :
222- self .close ()
223- raise e
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 )
224219
225- try :
226220 close_btn = self .driver \
227221 .find_element_by_css_selector ("div.overlayWindow i.icon-close" )
228222 close_btn .click ()
229223 except Exception as e :
230224 self .close ()
231225 raise e
232226
227+ def remove_color_from_icon (self ):
228+ """
229+ Remove the color from the most recent uploaded icon.
230+ This is because some SVG have colors in them and we don't want to
231+ force contributors to remove them in case people want the colored SVGs.
232+ The color removal is also necessary so that the Icomoon-generated
233+ icons fit within one font symbol/ligiature.
234+ """
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 ()
239+
240+ remove_color_btn = self .driver \
241+ .find_element_by_css_selector ("div.overlayWindow i.icon-droplet-cross" )
242+ remove_color_btn .click ()
243+
233244 def download_icomoon_fonts (self , zip_path : Path ):
234245 """
235246 Download the icomoon.zip from icomoon.io.
0 commit comments