1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-12 01:24:42 +02:00

Added zoomed in snapshot for peek scripts

This commit is contained in:
Thomas Bui
2020-12-28 18:32:49 -08:00
parent 4ec9d85805
commit eb6884db84
15 changed files with 159 additions and 28 deletions

View File

@@ -118,10 +118,13 @@ class SeleniumRunner:
print("JSON file uploaded.")
def upload_svgs(self, svgs: List[str]):
def upload_svgs(self, svgs: List[str], screenshot_folder: str=""):
"""
Upload the SVGs provided in folder_info
:param svgs: a list of svg Paths that we'll upload to icomoon.
: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.
"""
try:
print("Uploading SVGs...")
@@ -133,17 +136,20 @@ class SeleniumRunner:
self.click_hamburger_input()
for svg in svgs:
for i in range(len(svgs)):
import_btn = self.driver.find_element_by_css_selector(
"li.file input[type=file]"
)
import_btn.send_keys(svg)
print(f"Uploaded {svg}")
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()
self.remove_color_from_icon(screenshot_folder, i)
# take a screenshot of the icons that were just added
self.driver.save_screenshot("new_icons.png");
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']"))
@@ -191,11 +197,15 @@ class SeleniumRunner:
)
dismiss_btn.click()
except SeleniumTimeoutException:
pass
pass # nothing found => everything is good
def remove_color_from_icon(self):
def remove_color_from_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.
"""
try:
@@ -216,8 +226,11 @@ 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
# 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

View File

@@ -145,3 +145,18 @@ def rename_extracted_files(extract_path: str):
os.replace(dict_["old"], dict_["new"])
print("Files renamed")
def create_screenshot_folder(dir, screenshot_name: str="screenshots"):
"""
Create a screenshots folder in the dir.
:param dir, the dir where we want to create the folder.
:param screenshot_name, the name of the screenshot folder.
:raise Exception if the dir provided is not a directory.
:return the string name of the screenshot folder.
"""
folder = Path(dir).resolve()
if not folder.is_dir():
raise Exception(f"This is not a dir: {str(folder)}. \ndir must be a valid directory")
folder.mkdir(screenshot_name, exist_ok=True)
return str(folder)

View File

@@ -1,8 +1,7 @@
from pathlib import Path
from argparse import ArgumentParser
from build_assets.PathResolverAction import PathResolverAction
def get_commandline_args():
def get_commandline_args(peek_mode=False):
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
parser.add_argument("--headless",
@@ -26,8 +25,11 @@ def get_commandline_args():
action=PathResolverAction)
parser.add_argument("download_path",
help="The path where you'd like to download the Icomoon files to",
help="The download destination of the Icomoon files",
action=PathResolverAction)
if peek_mode:
parser.add_argument("--pr_title",
help="The title of the PR that we are peeking at")
return parser.parse_args()
return parser.parse_args()