Skip to content

Commit

Permalink
logging and toast error improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Feb 2, 2024
1 parent fdf20df commit 6d3d019
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/dropzone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provides an error-handling class and file-upload function to allow interaction with dropzones (from DropzoneJS)"""

import logging
import time
from dataclasses import dataclass
from pathlib import Path
Expand All @@ -10,6 +11,8 @@
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

logging.basicConfig(level=logging.WARNING, format="%(asctime)s : %(levelname)s : %(message)s")


class ToastErrorException(BaseException):
pass
Expand Down Expand Up @@ -37,7 +40,9 @@ def check_report_toast_error(self) -> None:
toast_message = toast_error_box.find_element(By.CLASS_NAME, "toast-message").text
raise ToastErrorException(toast_message)
except TimeoutException:
pass
logging.info("No toast message found")
except NoSuchElementException:
logging.info("No toast error or error message found")

def check_report_dropzone_upload_error(self) -> None:
"""Wait for timeout window and, if dropzone error message appears first, raise an exception with the content of the error message"""
Expand All @@ -48,7 +53,7 @@ def check_report_dropzone_upload_error(self) -> None:
dropzone_error_message = dropzone_error_box.find_element(By.TAG_NAME, "span").get_attribute("innerHTML")
raise DropzoneException(dropzone_error_message)
except TimeoutException:
pass
logging.info("No dropzone error found")

def check_report_upload_percentage(self) -> None:
"""Check if dropzone progress bar is present and, if so, raise an exception with the current progress percentage"""
Expand All @@ -58,7 +63,7 @@ def check_report_upload_percentage(self) -> None:
upload_progress = float(upload_progress_bar_width_filled) / float(upload_progress_bar_width)
raise LongUploadException(f"File upload timed out at {upload_progress:.0f}%")
except NoSuchElementException:
pass
logging.info("No file progress bars found")


def add_file_to_dropzone(driver: webdriver, timeout: float, upload_file: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/forge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def login(self, driver: webdriver, urls: ForgeURLs) -> None:
login_button = WebDriverWait(driver, self.timeout).until(EC.element_to_be_clickable((By.CLASS_NAME, "registerbtn")))
login_button.click()
except TimeoutException:
pass
logging.info("No username or password field found, or login button is not clickable.")

def open_items_list(self, driver: webdriver, urls: ForgeURLs) -> None:
"""Open the manage craft page, raising an exception if the item table size selector isn't found."""
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_readme_html(new_file: Path) -> str:
def get_build_file(file_path: PurePath, env_file: str) -> Path:
"""Combines PurePath and file name into a Path object, ensure that a file exists there, and returns the Path"""
new_file = Path(file_path, env_file)
logging.debug("File upload path determined to be: %s", new_file)
logging.info("File upload path determined to be: %s", new_file)
if not new_file.is_file():
raise FileNotFoundError(f"File at {str(new_file)} is not found.")
return new_file
Expand Down

0 comments on commit 6d3d019

Please sign in to comment.