1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-09 08:06:32 +02:00

Workflow now takes path to geckodriver instead of manually adding it to PATH

This commit is contained in:
Thomas Bui
2020-08-21 10:35:40 -07:00
parent 330c994480
commit d3ef8476e7
4 changed files with 55 additions and 39 deletions

View File

@@ -34,25 +34,26 @@ class SeleniumRunner:
ICOMOON_URL = "https://icomoon.io/app/#/select"
def __init__(self, icomoon_json_path: str, download_path: str,
headless=True):
geckodriver_path: str, headless):
"""
Create a SeleniumRunner object.
:param icomoon_json_path: a path to the iconmoon.json.
:param download_path: the location where you want to download
the icomoon.zip to.
svg folders.
:param geckodriver_path: the path to the firefox executable.
:param headless: whether to run browser in headless (no UI) mode.
"""
self.icomoon_json_path = icomoon_json_path
self.download_path = download_path
self.headless = headless
self.driver = None
self.set_options()
self.set_options(geckodriver_path, headless)
def set_options(self):
def set_options(self, geckodriver_path: str, headless: bool):
"""
Build the WebDriver with Firefox Options allowing downloads and
set download to download_path.
:param geckodriver_path: the path to the firefox executable.
:param headless: whether to run browser in headless (no UI) mode.
:raises AssertionError: if the page title does not contain
"IcoMoon App".
@@ -66,9 +67,9 @@ class SeleniumRunner:
# set the default download path to downloadPath
options.set_preference("browser.download.folderList", 2)
options.set_preference("browser.download.dir", self.download_path)
options.headless = self.headless
options.headless = headless
self.driver = WebDriver(options=options)
self.driver = WebDriver(options=options, executable_path=geckodriver_path)
self.driver.get(self.ICOMOON_URL)
assert "IcoMoon App" in self.driver.title
@@ -124,7 +125,7 @@ class SeleniumRunner:
)
import_btn.send_keys(svg)
print(f"Uploaded {svg}")
self.test_for_possible_alert()
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
self.remove_color_from_icon()
self.click_hamburger_input()
@@ -158,14 +159,18 @@ class SeleniumRunner:
self.close()
raise e
def test_for_possible_alert(self):
def test_for_possible_alert(self, wait_period: float, btn_text: str):
"""
Test for the possible alert when we upload the svgs.
:param wait_period: the wait period for the possible alert
in seconds.
:param btn_text: the text that the alert's button will have.
:return: None.
"""
try:
dismiss_btn = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC, 0.15).until(
ec.element_to_be_clickable((By.XPATH, "//div[@class='overlay']//button[text()='Dismiss']"))
dismiss_btn = WebDriverWait(self.driver, wait_period, 0.15).until(
ec.element_to_be_clickable(
(By.XPATH, f"//div[@class='overlay']//button[text()='{btn_text}']"))
)
dismiss_btn.click()
except SeleniumTimeoutException:
@@ -181,16 +186,26 @@ class SeleniumRunner:
ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div"))
)
recently_uploaded_icon.click()
except Exception as e:
self.close()
raise e
color_tab = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
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"))
)
color_tab.click()
color_tab = self.driver\
remove_color_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
color_tab.click()
remove_color_btn.click()
except SeleniumTimeoutException:
pass
except Exception as e:
self.close()
raise e
try:
close_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-close")
close_btn.click()
@@ -208,25 +223,19 @@ class SeleniumRunner:
"a[href='#/select/font']"
).click()
button = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
)
button.click()
download_btn.click()
print("Font files downloaded.")
except Exception as e:
self.close()
raise e
def close(self, err=True):
def close(self):
"""
Close the SeleniumRunner instance.
:param err, whether this was called due to an error or not.
"""
print("Closing down SeleniumRunner...")
self.driver.quit()
if err:
code = 1
else:
code = 0
exit(code)

View File

@@ -12,12 +12,16 @@ def main():
help="Whether to run the browser in headless/no UI mode",
action="store_true")
parser.add_argument("geckodriver_path",
help="The path to the firefox executable file",
action=PathResolverAction)
parser.add_argument("icomoon_json_path",
help="The path to the icomoon_test.json aka the selection.json created by Icomoon",
help="The path to the icomoon.json aka the selection.json created by Icomoon",
action=PathResolverAction)
parser.add_argument("devicon_json_path",
help="The path to the devicon_test.json",
help="The path to the devicon.json",
action=PathResolverAction)
parser.add_argument("icons_folder_path",
@@ -31,7 +35,7 @@ def main():
args = parser.parse_args()
runner = SeleniumRunner(args.icomoon_json_path, args.download_path,
args.headless)
args.geckodriver_path, args.headless)
runner.upload_icomoon()
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
@@ -39,11 +43,11 @@ def main():
runner.upload_svgs(svgs)
runner.download_icomoon_fonts()
zip_name = "devicon-v1.0.zip"
zip_path = str(Path(args.download_path, zip_name))
# zip_name = "devicon-v1.0.zip"
# zip_path = str(Path(args.download_path, zip_name))
# filehandler.extract_files(zip_path, args.download_path)
# filehandler.rename_extracted_files(args.download_path)
runner.close(err=False)
runner.close()
print("Task completed.")

View File

@@ -15,7 +15,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r ./.github/scripts/requirements.txt
- name: Add geckodriver to PATH
run: set PATH=${{ format('{0}/.github/scripts/build_assets/geckodriver.exe', github.workspace) }};%PATH%
- name: Run icomoon_upload.py
run: python ./.github/scripts/icomoon_upload.py ./icomoon.json ./devicon.json ./icons ./ --headless
run: >
python ./.github/scripts/icomoon_upload.py ./.github/scripts/build_assets/geckodriver.exe
./icomoon.json ./devicon.json ./icons ./ --headless

View File

@@ -143,16 +143,18 @@
"tags": ["language"],
"versions": {
"svg": ["original", "line", "plain"],
"font": []
}
"font": ["plain"]
},
"aliases": []
},
{
"name": "clojurescript",
"tags": ["language"],
"versions": {
"svg": ["original", "plain"],
"font": []
}
"font": ["plain"]
},
"aliases": []
},
{
"name": "codeigniter",
@@ -608,7 +610,8 @@
"versions": {
"svg": ["plain"],
"font": ["plain"]
}
},
"aliases": []
},
{
"name": "mongodb",