Refactor logging statements in UI tests

This commit is contained in:
Théophile Diot 2024-02-07 16:25:11 +01:00
parent 7592bb56b4
commit 36c157d4be
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
3 changed files with 8 additions and 8 deletions

View file

@ -1,6 +1,6 @@
from contextlib import suppress
from functools import partial
from logging import DEBUG, INFO, _nameToLevel, basicConfig, info
from logging import DEBUG, INFO, _nameToLevel, basicConfig, error as log_error, info as log_info, warning as log_warning
from os import getenv, listdir, sep
from pathlib import Path
from time import sleep
@ -35,17 +35,17 @@ while not ready:
status_code = get(f"http://{DEFAULT_SERVER}/setup").status_code
if status_code > 500 and status_code != 502:
print("An error occurred with the server, exiting ...", flush=True)
log_error("An error occurred with the server, exiting ...")
exit(1)
ready = status_code < 400
if retries > 20:
print("UI took too long to be ready, exiting ...", flush=True)
log_error("UI took too long to be ready, exiting ...")
exit(1)
elif not ready:
retries += 1
print("Waiting for UI to be ready, retrying in 5s ...", flush=True)
log_warning("Waiting for UI to be ready, retrying in 5s ...")
sleep(5)
driver_func = partial(webdriver.Firefox, service=Service(log_output="./geckodriver.log"), options=FIREFOX_OPTIONS)
@ -58,6 +58,6 @@ if TEST_TYPE == "dev":
DRIVER = driver_func()
info("UI is ready, starting tests ...")
log_info("UI is ready, starting tests ...")
__all__ = ("DEFAULT_SERVER", "TEST_TYPE", "DRIVER")

View file

@ -20,7 +20,7 @@ try:
file_content_elem = safe_get_element(DRIVER, By.XPATH, "//div[@data-cache-modal-editor='']/div[@class='ace_scroller']//div[@class='ace_line']")
assert isinstance(file_content_elem, WebElement), "The file content element is not an instance of WebElement"
if file_content_elem.text.strip() != "Download file to view content":
print("The cache file content is not correct, exiting ...", flush=True)
log_exception("The cache file content is not correct, exiting ...")
exit(1)
assert_button_click(DRIVER, "//button[@data-cache-modal-submit='']")

View file

@ -43,10 +43,10 @@ try:
with suppress(TimeoutException):
safe_get_element(DRIVER, By.XPATH, "//ul[@data-reports-list='']/li[not(contains(@class, 'hidden'))]", error=True)
print("The keyword filter is not working, exiting ...", flush=True)
log_error("The keyword filter is not working, exiting ...")
exit(1)
print("The reports have been filtered", flush=True)
log_info("The reports have been filtered")
log_info("✅ Reports page tests finished successfully")
except SystemExit as e: