1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-14 10:34:14 +02:00

Added color tab error handling and better logging

This commit is contained in:
Thomas Bui
2021-01-01 00:42:53 -08:00
parent 6c0122648a
commit 1038b7a774
3 changed files with 79 additions and 102 deletions

View File

@@ -89,20 +89,11 @@ class SeleniumRunner:
:raises TimeoutException: happens when elements are not found. :raises TimeoutException: happens when elements are not found.
""" """
print("Uploading icomoon.json file...") print("Uploading icomoon.json file...")
try:
self.click_hamburger_input() self.click_hamburger_input()
# find the file input and enter the file path # find the file input and enter the file path
import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input") import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
import_btn.send_keys(icomoon_json_path) import_btn.send_keys(icomoon_json_path)
except SeleniumTimeoutException as e:
print(e.stacktrace)
print("Selenium timed out. Couldn't find import button.")
self.close()
raise e
except Exception as e:
self.close()
raise e
try: try:
confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until( confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until(
@@ -110,11 +101,8 @@ class SeleniumRunner:
) )
confirm_btn.click() confirm_btn.click()
except SeleniumTimeoutException as e: except SeleniumTimeoutException as e:
print(e.stacktrace) raise Exception("Cannot find the confirm button when uploading the icomoon.json" \
print("Cannot find the confirm button when uploading the icomoon.json", "Ensure that the icomoon.json is in the correct format for Icomoon.io")
"Ensure that the icomoon.json is in the correct format for Icomoon.io",
sep='\n')
self.close()
print("JSON file uploaded.") print("JSON file uploaded.")
@@ -126,7 +114,6 @@ class SeleniumRunner:
the value is provided, it means the user want to take a screenshot the value is provided, it means the user want to take a screenshot
of each icon. of each icon.
""" """
try:
print("Uploading SVGs...") print("Uploading SVGs...")
edit_mode_btn = self.driver.find_element_by_css_selector( edit_mode_btn = self.driver.find_element_by_css_selector(
@@ -149,16 +136,7 @@ class SeleniumRunner:
new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve()) new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
self.driver.save_screenshot(new_icons_path); self.driver.save_screenshot(new_icons_path);
# select all the svgs so that the newly added svg are part of the collection
self.click_hamburger_input()
select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
)
select_all_button.click()
print("Finished uploading the svgs...") print("Finished uploading the svgs...")
except Exception as e:
self.close()
raise e
def click_hamburger_input(self): def click_hamburger_input(self):
""" """
@@ -167,7 +145,6 @@ class SeleniumRunner:
input two times before the menu appears. input two times before the menu appears.
:return: None. :return: None.
""" """
try:
hamburger_input = self.driver.find_element_by_xpath( hamburger_input = self.driver.find_element_by_xpath(
"(//i[@class='icon-menu'])[2]" "(//i[@class='icon-menu'])[2]"
) )
@@ -178,9 +155,6 @@ class SeleniumRunner:
while not menu_appear_callback(self.driver): while not menu_appear_callback(self.driver):
hamburger_input.click() hamburger_input.click()
except Exception as e:
self.close()
raise e
def test_for_possible_alert(self, wait_period: float, btn_text: str): def test_for_possible_alert(self, wait_period: float, btn_text: str):
""" """
@@ -204,7 +178,6 @@ class SeleniumRunner:
Click on the most recently added icon so we can remove the colors Click on the most recently added icon so we can remove the colors
and take a snapshot if needed. and take a snapshot if needed.
""" """
try:
recently_uploaded_icon = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until( 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")) ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div"))
) )
@@ -220,9 +193,6 @@ class SeleniumRunner:
close_btn = self.driver \ close_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-close") .find_element_by_css_selector("div.overlayWindow i.icon-close")
close_btn.click() close_btn.click()
except Exception as e:
self.close()
raise e
def remove_color_from_icon(self): def remove_color_from_icon(self):
""" """
@@ -232,6 +202,7 @@ class SeleniumRunner:
The color removal is also necessary so that the Icomoon-generated The color removal is also necessary so that the Icomoon-generated
icons fit within one font symbol/ligiature. icons fit within one font symbol/ligiature.
""" """
try:
color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until( color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until(
ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet")) ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet"))
) )
@@ -240,17 +211,26 @@ class SeleniumRunner:
remove_color_btn = self.driver \ remove_color_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross") .find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
remove_color_btn.click() remove_color_btn.click()
except SeleniumTimeoutException:
pass # do nothing cause sometimes, the color tab doesn't appear in the site
def download_icomoon_fonts(self, zip_path: Path): def download_icomoon_fonts(self, zip_path: Path):
""" """
Download the icomoon.zip from icomoon.io. Download the icomoon.zip from icomoon.io.
:param zip_path: the path to the zip file after it's downloaded. :param zip_path: the path to the zip file after it's downloaded.
""" """
try: # select all the svgs so that the newly added svg are part of the collection
self.click_hamburger_input()
select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
)
select_all_button.click()
print("Downloading Font files...") print("Downloading Font files...")
self.driver.find_element_by_css_selector( font_tab = self.driver.find_element_by_css_selector(
"a[href='#/select/font']" "a[href='#/select/font']"
).click() )
font_tab.click()
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue") self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until( download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
@@ -261,9 +241,6 @@ class SeleniumRunner:
print("Font files downloaded.") print("Font files downloaded.")
else: else:
raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.") raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")
except Exception as e:
self.close()
raise e
def wait_for_zip(self, zip_path: Path) -> bool: def wait_for_zip(self, zip_path: Path) -> bool:
""" """

View File

@@ -32,7 +32,7 @@ def main():
filehandler.rename_extracted_files(args.download_path) filehandler.rename_extracted_files(args.download_path)
print("Task completed.") print("Task completed.")
except TimeoutException as e: except TimeoutException as e:
sys.exit("Selenium Time Out Error: \n" + e) sys.exit("Selenium Time Out Error: \n" + str(e))
except Exception as e: except Exception as e:
sys.exit(e) sys.exit(e)
finally: finally:

View File

@@ -38,7 +38,7 @@ def main():
runner.upload_svgs(svgs, screenshot_folder) runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.") print("Task completed.")
except TimeoutException as e: except TimeoutException as e:
sys.exit("Selenium Time Out Error: \n" + e) sys.exit("Selenium Time Out Error: \n" + str(e))
except Exception as e: except Exception as e:
sys.exit(e) sys.exit(e)
finally: finally: