Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated CONTRIBUTING #416

Merged
merged 8 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 80 additions & 103 deletions .github/scripts/build_assets/SeleniumRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,20 @@ def upload_icomoon(self, icomoon_json_path: str):
: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
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)

try:
confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until(
ec.element_to_be_clickable((By.XPATH, "//div[@class='overlay']//button[text()='Yes']"))
)
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.")

Expand All @@ -126,39 +114,29 @@ def upload_svgs(self, svgs: List[str], screenshot_folder: str=""):
the value is provided, it means the user want to take a screenshot
of each icon.
"""
try:
print("Uploading SVGs...")
print("Uploading SVGs...")

edit_mode_btn = self.driver.find_element_by_css_selector(
"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]"
)
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']"))
edit_mode_btn = self.driver.find_element_by_css_selector(
"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]"
)
select_all_button.click()
print("Finished uploading the svgs...")
except Exception as e:
self.close()
raise e
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);

print("Finished uploading the svgs...")

def click_hamburger_input(self):
"""
Expand All @@ -167,20 +145,16 @@ def click_hamburger_input(self):
input two times before the menu appears.
:return: None.
"""
try:
hamburger_input = self.driver.find_element_by_xpath(
"(//i[@class='icon-menu'])[2]"
)
hamburger_input = self.driver.find_element_by_xpath(
"(//i[@class='icon-menu'])[2]"
)

menu_appear_callback = ec.element_to_be_clickable(
(By.CSS_SELECTOR, "h1 ul.menuList2")
)
menu_appear_callback = ec.element_to_be_clickable(
(By.CSS_SELECTOR, "h1 ul.menuList2")
)

while not menu_appear_callback(self.driver):
hamburger_input.click()
except Exception as e:
self.close()
raise e
while not menu_appear_callback(self.driver):
hamburger_input.click()

def test_for_possible_alert(self, wait_period: float, btn_text: str):
"""
Expand All @@ -204,25 +178,21 @@ def click_on_just_added_icon(self, screenshot_folder: str, index: int):
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"))
)
recently_uploaded_icon.click()
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"))
)
recently_uploaded_icon.click()

self.remove_color_from_icon()
self.remove_color_from_icon()

if screenshot_folder:
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
self.driver.save_screenshot(screenshot_path)
print("Took screenshot and saved it at " + screenshot_path)
if screenshot_folder:
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
self.driver.save_screenshot(screenshot_path)
print("Took screenshot and saved it at " + screenshot_path)

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
close_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-close")
close_btn.click()

def remove_color_from_icon(self):
"""
Expand All @@ -232,38 +202,45 @@ def remove_color_from_icon(self):
The color removal is also necessary so that the Icomoon-generated
icons fit within one font symbol/ligiature.
"""
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()
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()

remove_color_btn = self.driver \
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
remove_color_btn.click()
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:
print("Downloading Font files...")
self.driver.find_element_by_css_selector(
"a[href='#/select/font']"
).click()

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"))
)
download_btn.click()
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.")
except Exception as e:
self.close()
raise e
# 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...")
font_tab = self.driver.find_element_by_css_selector(
"a[href='#/select/font']"
)
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(
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
)
download_btn.click()
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:
"""
Expand Down
11 changes: 6 additions & 5 deletions .github/scripts/icomoon_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import sys
from selenium.common.exceptions import TimeoutException

# pycharm complains that build_assets is an unresolved ref
Expand All @@ -11,8 +12,7 @@ def main():
args = arg_getters.get_selenium_runner_args()
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
if len(new_icons) == 0:
print("No files need to be uploaded. Ending script...")
return
sys.exit("No files need to be uploaded. Ending script...")

# print list of new icons
print("List of new icons:", *new_icons, sep = "\n")
Expand All @@ -32,10 +32,11 @@ def main():
filehandler.rename_extracted_files(args.download_path)
print("Task completed.")
except TimeoutException as e:
print(e)
print(e.stacktrace)
sys.exit("Selenium Time Out Error: \n" + str(e))
except Exception as e:
sys.exit(e)
finally:
runner.close()
runner.close()


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/icomoon_peek.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def main():
runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.")
except TimeoutException as e:
print("Selenium Time Out Error: ", e.stacktrace, sep='\n')
sys.exit("Selenium Time Out Error: \n" + str(e))
except Exception as e:
print(e)
sys.exit(e)
finally:
runner.close()
runner.close()


def find_object_added_in_this_pr(icons: List[dict], pr_title: str):
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: npm run build-css
- name: Upload screenshot of the newly made icons
id: imgur_step
uses: devicons/public-upload-to-imgur@v2
uses: devicons/public-upload-to-imgur@v2.1
if: success()
with:
path: ./new_icons.png
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/peek_icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name}}
- name: Setup Python v3.8
uses: actions/setup-python@v2
with:
Expand All @@ -36,14 +33,14 @@ jobs:
path: ./geckodriver.log
- name: Upload screenshot of the newly made icons
id: icons_overview_img_step
uses: devicons/public-upload-to-imgur@v2
uses: devicons/public-upload-to-imgur@v2.1
if: success()
with:
path: ./screenshots/new_icons.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Upload zoomed in screenshot of the newly made icons
id: icons_detailed_img_step
uses: devicons/public-upload-to-imgur@v2
uses: devicons/public-upload-to-imgur@v2.1
if: success()
with:
path: ./screenshots/screenshot_*.png
Expand Down
Loading