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

Refactored take screenshot and remove color functions

This commit is contained in:
Thomas Bui
2020-12-29 15:44:57 -08:00
parent 8a5ff05f01
commit c388503d28
2 changed files with 20 additions and 26 deletions

View File

@@ -143,7 +143,7 @@ class SeleniumRunner:
import_btn.send_keys(svgs[i]) import_btn.send_keys(svgs[i])
print(f"Uploaded {svgs[i]}") print(f"Uploaded {svgs[i]}")
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss") 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 # take a screenshot of the icons that were just added
new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve()) new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
@@ -199,43 +199,24 @@ class SeleniumRunner:
except SeleniumTimeoutException: except SeleniumTimeoutException:
pass # nothing found => everything is good 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. Click on the most recently added icon so we can remove the colors
:param screenshot_folder: the name of the screenshot_folder. If and take a snapshot if needed.
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.
""" """
try: 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()
except Exception as e:
self.close()
raise e
try: self.remove_color_from_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()
# take a screenshot before closing the pop up
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)
except Exception as e: print("Took screenshot and saved it at " + screenshot_path)
self.close()
raise e
try:
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()
@@ -243,6 +224,19 @@ class SeleniumRunner:
self.close() self.close()
raise e 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): def download_icomoon_fonts(self, zip_path: Path):
""" """
Download the icomoon.zip from icomoon.io. Download the icomoon.zip from icomoon.io.

View File

@@ -31,7 +31,7 @@ def main():
runner = None runner = None
try: try:
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless) 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) runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.") print("Task completed.")
except TimeoutException as e: except TimeoutException as e: