From c388503d28e9a30ba75f34ec29731b2963c5735d Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Tue, 29 Dec 2020 15:44:57 -0800 Subject: [PATCH] Refactored take screenshot and remove color functions --- .../scripts/build_assets/SeleniumRunner.py | 44 ++++++++----------- .github/scripts/icomoon_peek.py | 2 +- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.github/scripts/build_assets/SeleniumRunner.py b/.github/scripts/build_assets/SeleniumRunner.py index b4df610e..fac564be 100644 --- a/.github/scripts/build_assets/SeleniumRunner.py +++ b/.github/scripts/build_assets/SeleniumRunner.py @@ -143,7 +143,7 @@ class SeleniumRunner: import_btn.send_keys(svgs[i]) print(f"Uploaded {svgs[i]}") self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss") - self.remove_color_from_icon(screenshot_folder, i) + self.click_on_just_added_icon(screenshot_folder, i) # take a screenshot of the icons that were just added new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve()) @@ -199,43 +199,24 @@ class SeleniumRunner: except SeleniumTimeoutException: pass # nothing found => everything is good - def remove_color_from_icon(self, screenshot_folder: str, index: int): + def click_on_just_added_icon(self, screenshot_folder: str, index: int): """ - Remove the color from the most recent uploaded icon. - :param screenshot_folder: the name of the screenshot_folder. If - the value is provided, it means the user want to take a screenshot - of each icon. - :param index, index of the icon being uploaded. Used for naming the screenshot. - :return: None. + Click on the most recently added icon so we can remove the colors + and take a snapshot if needed. """ try: recently_uploaded_icon = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until( ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div")) ) recently_uploaded_icon.click() - except Exception as e: - self.close() - raise e - try: - color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until( - ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet")) - ) - color_tab.click() + self.remove_color_from_icon() - remove_color_btn = self.driver \ - .find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross") - remove_color_btn.click() - - # take a screenshot before closing the pop up if screenshot_folder: screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve()) self.driver.save_screenshot(screenshot_path) - except Exception as e: - self.close() - raise e + print("Took screenshot and saved it at " + screenshot_path) - try: close_btn = self.driver \ .find_element_by_css_selector("div.overlayWindow i.icon-close") close_btn.click() @@ -243,6 +224,19 @@ class SeleniumRunner: self.close() raise e + def remove_color_from_icon(self): + """ + Remove the color from the most recent uploaded icon. + """ + color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until( + ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet")) + ) + color_tab.click() + + remove_color_btn = self.driver \ + .find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross") + remove_color_btn.click() + def download_icomoon_fonts(self, zip_path: Path): """ Download the icomoon.zip from icomoon.io. diff --git a/.github/scripts/icomoon_peek.py b/.github/scripts/icomoon_peek.py index 925c3b34..2533fde7 100644 --- a/.github/scripts/icomoon_peek.py +++ b/.github/scripts/icomoon_peek.py @@ -31,7 +31,7 @@ def main(): runner = None try: runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless) - svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path) + svgs = filehandler.get_svgs_paths(filtered_icons, args.icons_folder_path) runner.upload_svgs(svgs, screenshot_folder) print("Task completed.") except TimeoutException as e: