mirror of
https://github.com/konpa/devicon.git
synced 2025-08-14 02:24:04 +02:00
Added color tab error handling and better logging
This commit is contained in:
175
.github/scripts/build_assets/SeleniumRunner.py
vendored
175
.github/scripts/build_assets/SeleniumRunner.py
vendored
@@ -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,39 +114,29 @@ 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(
|
||||||
"div.btnBar button i.icon-edit"
|
"div.btnBar button i.icon-edit"
|
||||||
|
)
|
||||||
|
edit_mode_btn.click()
|
||||||
|
|
||||||
|
self.click_hamburger_input()
|
||||||
|
|
||||||
|
for i in range(len(svgs)):
|
||||||
|
import_btn = self.driver.find_element_by_css_selector(
|
||||||
|
"li.file input[type=file]"
|
||||||
)
|
)
|
||||||
edit_mode_btn.click()
|
import_btn.send_keys(svgs[i])
|
||||||
|
print(f"Uploaded {svgs[i]}")
|
||||||
|
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
|
||||||
|
self.click_on_just_added_icon(screenshot_folder, i)
|
||||||
|
|
||||||
self.click_hamburger_input()
|
# take a screenshot of the icons that were just added
|
||||||
|
new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
|
||||||
|
self.driver.save_screenshot(new_icons_path);
|
||||||
|
|
||||||
for i in range(len(svgs)):
|
print("Finished uploading the svgs...")
|
||||||
import_btn = self.driver.find_element_by_css_selector(
|
|
||||||
"li.file input[type=file]"
|
|
||||||
)
|
|
||||||
import_btn.send_keys(svgs[i])
|
|
||||||
print(f"Uploaded {svgs[i]}")
|
|
||||||
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
|
|
||||||
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())
|
|
||||||
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):
|
def click_hamburger_input(self):
|
||||||
"""
|
"""
|
||||||
@@ -167,20 +145,16 @@ 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]"
|
)
|
||||||
)
|
|
||||||
|
|
||||||
menu_appear_callback = ec.element_to_be_clickable(
|
menu_appear_callback = ec.element_to_be_clickable(
|
||||||
(By.CSS_SELECTOR, "h1 ul.menuList2")
|
(By.CSS_SELECTOR, "h1 ul.menuList2")
|
||||||
)
|
)
|
||||||
|
|
||||||
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,25 +178,21 @@ 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"))
|
)
|
||||||
)
|
recently_uploaded_icon.click()
|
||||||
recently_uploaded_icon.click()
|
|
||||||
|
|
||||||
self.remove_color_from_icon()
|
self.remove_color_from_icon()
|
||||||
|
|
||||||
if screenshot_folder:
|
if screenshot_folder:
|
||||||
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
|
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
|
||||||
self.driver.save_screenshot(screenshot_path)
|
self.driver.save_screenshot(screenshot_path)
|
||||||
print("Took screenshot and saved it at " + screenshot_path)
|
print("Took screenshot and saved it at " + screenshot_path)
|
||||||
|
|
||||||
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,38 +202,45 @@ 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.
|
||||||
"""
|
"""
|
||||||
color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until(
|
try:
|
||||||
ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet"))
|
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()
|
)
|
||||||
|
color_tab.click()
|
||||||
|
|
||||||
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
|
||||||
print("Downloading Font files...")
|
self.click_hamburger_input()
|
||||||
self.driver.find_element_by_css_selector(
|
select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
|
||||||
"a[href='#/select/font']"
|
ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
|
||||||
).click()
|
)
|
||||||
|
select_all_button.click()
|
||||||
|
|
||||||
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
|
print("Downloading Font files...")
|
||||||
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
font_tab = self.driver.find_element_by_css_selector(
|
||||||
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
|
"a[href='#/select/font']"
|
||||||
)
|
)
|
||||||
download_btn.click()
|
font_tab.click()
|
||||||
if self.wait_for_zip(zip_path):
|
|
||||||
print("Font files downloaded.")
|
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
|
||||||
else:
|
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
||||||
raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")
|
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
|
||||||
except Exception as e:
|
)
|
||||||
self.close()
|
download_btn.click()
|
||||||
raise e
|
if self.wait_for_zip(zip_path):
|
||||||
|
print("Font files downloaded.")
|
||||||
|
else:
|
||||||
|
raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")
|
||||||
|
|
||||||
def wait_for_zip(self, zip_path: Path) -> bool:
|
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)
|
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:
|
||||||
|
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)
|
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:
|
||||||
|
Reference in New Issue
Block a user