@@ -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 .remove_color_from_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,11 +197,15 @@ 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 remove_color_from_icon (self , screenshot_folder : str , index : int ):
197203 """
198204 Remove the color from the most recent uploaded icon.
205+ :param screenshot_folder: the name of the screenshot_folder. If
206+ the value is provided, it means the user want to take a screenshot
207+ of each icon.
208+ :param index, index of the icon being uploaded. Used for naming the screenshot.
199209 :return: None.
200210 """
201211 try :
@@ -216,8 +226,11 @@ def remove_color_from_icon(self):
216226 remove_color_btn = self .driver \
217227 .find_element_by_css_selector ("div.overlayWindow i.icon-droplet-cross" )
218228 remove_color_btn .click ()
219- except SeleniumTimeoutException :
220- pass
229+
230+ # take a screenshot before closing the pop up
231+ if screenshot_folder :
232+ screenshot_path = str (Path (screenshot_folder , f"screenshot_{ index } .png" ).resolve ())
233+ self .driver .save_screenshot (screenshot_path )
221234 except Exception as e :
222235 self .close ()
223236 raise e
0 commit comments