mirror of
https://github.com/konpa/devicon.git
synced 2025-08-12 09:34:36 +02:00
Added color tab error handling and better logging
This commit is contained in:
53
.github/scripts/build_assets/SeleniumRunner.py
vendored
53
.github/scripts/build_assets/SeleniumRunner.py
vendored
@@ -89,20 +89,11 @@ class SeleniumRunner:
|
||||
:raises TimeoutException: happens when elements are not found.
|
||||
"""
|
||||
print("Uploading icomoon.json file...")
|
||||
try:
|
||||
self.click_hamburger_input()
|
||||
|
||||
# find the file input and enter the file path
|
||||
import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
|
||||
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:
|
||||
confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until(
|
||||
@@ -110,11 +101,8 @@ class SeleniumRunner:
|
||||
)
|
||||
confirm_btn.click()
|
||||
except SeleniumTimeoutException as e:
|
||||
print(e.stacktrace)
|
||||
print("Cannot find the confirm button when uploading the icomoon.json",
|
||||
"Ensure that the icomoon.json is in the correct format for Icomoon.io",
|
||||
sep='\n')
|
||||
self.close()
|
||||
raise Exception("Cannot find the confirm button when uploading the icomoon.json" \
|
||||
"Ensure that the icomoon.json is in the correct format for Icomoon.io")
|
||||
|
||||
print("JSON file uploaded.")
|
||||
|
||||
@@ -126,7 +114,6 @@ class SeleniumRunner:
|
||||
the value is provided, it means the user want to take a screenshot
|
||||
of each icon.
|
||||
"""
|
||||
try:
|
||||
print("Uploading SVGs...")
|
||||
|
||||
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())
|
||||
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...")
|
||||
except Exception as e:
|
||||
self.close()
|
||||
raise e
|
||||
|
||||
def click_hamburger_input(self):
|
||||
"""
|
||||
@@ -167,7 +145,6 @@ class SeleniumRunner:
|
||||
input two times before the menu appears.
|
||||
:return: None.
|
||||
"""
|
||||
try:
|
||||
hamburger_input = self.driver.find_element_by_xpath(
|
||||
"(//i[@class='icon-menu'])[2]"
|
||||
)
|
||||
@@ -178,9 +155,6 @@ class SeleniumRunner:
|
||||
|
||||
while not menu_appear_callback(self.driver):
|
||||
hamburger_input.click()
|
||||
except Exception as e:
|
||||
self.close()
|
||||
raise e
|
||||
|
||||
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
|
||||
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"))
|
||||
)
|
||||
@@ -220,9 +193,6 @@ class SeleniumRunner:
|
||||
close_btn = self.driver \
|
||||
.find_element_by_css_selector("div.overlayWindow i.icon-close")
|
||||
close_btn.click()
|
||||
except Exception as e:
|
||||
self.close()
|
||||
raise e
|
||||
|
||||
def remove_color_from_icon(self):
|
||||
"""
|
||||
@@ -232,6 +202,7 @@ class SeleniumRunner:
|
||||
The color removal is also necessary so that the Icomoon-generated
|
||||
icons fit within one font symbol/ligiature.
|
||||
"""
|
||||
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"))
|
||||
)
|
||||
@@ -240,17 +211,26 @@ class SeleniumRunner:
|
||||
remove_color_btn = self.driver \
|
||||
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
|
||||
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):
|
||||
"""
|
||||
Download the icomoon.zip from icomoon.io.
|
||||
: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...")
|
||||
self.driver.find_element_by_css_selector(
|
||||
font_tab = self.driver.find_element_by_css_selector(
|
||||
"a[href='#/select/font']"
|
||||
).click()
|
||||
)
|
||||
font_tab.click()
|
||||
|
||||
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
|
||||
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
||||
@@ -261,9 +241,6 @@ class SeleniumRunner:
|
||||
print("Font files downloaded.")
|
||||
else:
|
||||
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:
|
||||
"""
|
||||
|
2
.github/scripts/icomoon_build.py
vendored
2
.github/scripts/icomoon_build.py
vendored
@@ -32,7 +32,7 @@ def main():
|
||||
filehandler.rename_extracted_files(args.download_path)
|
||||
print("Task completed.")
|
||||
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:
|
||||
sys.exit(e)
|
||||
finally:
|
||||
|
2
.github/scripts/icomoon_peek.py
vendored
2
.github/scripts/icomoon_peek.py
vendored
@@ -38,7 +38,7 @@ def main():
|
||||
runner.upload_svgs(svgs, screenshot_folder)
|
||||
print("Task completed.")
|
||||
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:
|
||||
sys.exit(e)
|
||||
finally:
|
||||
|
Reference in New Issue
Block a user