Add cache page and reports page UI tests

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

43
tests/ui/cache_page.py Normal file
View file

@ -0,0 +1,43 @@
from logging import info as log_info, exception as log_exception
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from wizard import DRIVER
from utils import access_page, assert_button_click, safe_get_element
exit_code = 0
try:
log_info("Navigating to the cache page ...")
access_page(DRIVER, "/html/body/aside[1]/div[1]/div[3]/ul/li[7]/a", "cache")
log_info("Trying to open a cache file ...")
assert_button_click(DRIVER, "//div[@data-cache-element='mmdb-asn/asn.mmdb']")
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)
exit(1)
assert_button_click(DRIVER, "//button[@data-cache-modal-submit='']")
sleep(3)
log_info("The cache file content is correct")
log_info("✅ Cache page tests finished successfully")
except SystemExit as e:
exit_code = e.code
except KeyboardInterrupt:
exit_code = 1
except:
log_exception("Something went wrong, exiting ...")
DRIVER.save_screenshot("error.png")
exit_code = 1
finally:
DRIVER.quit()
exit(exit_code)

62
tests/ui/reports_page.py Normal file
View file

@ -0,0 +1,62 @@
from contextlib import suppress
from logging import info as log_info, error as log_error, exception as log_exception
from time import sleep
from requests import get
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import TimeoutException
from wizard import DRIVER
from utils import access_page, safe_get_element
exit_code = 0
try:
log_info("Navigating to the reports page ...")
access_page(DRIVER, "/html/body/aside[1]/div[1]/div[3]/ul/li[8]/a", "reports")
with suppress(TimeoutException):
safe_get_element(DRIVER, By.XPATH, "/html/body/main/div/div/div/h5", error=True)
log_info("No reports found, generating some ...")
for _ in range(5):
get("http://www.example.com/?id=/etc/passwd")
sleep(1)
sleep(7)
DRIVER.refresh()
log_info("Trying to filter the reports ...")
reports_list = safe_get_element(DRIVER, By.XPATH, "//ul[@data-reports-list='']/li", multiple=True)
assert isinstance(reports_list, list), "Reports list is not a list"
if not reports_list:
log_error("No reports found, exiting ...")
exit(1)
filter_input = safe_get_element(DRIVER, By.ID, "keyword")
assert isinstance(filter_input, WebElement), "Keyword filter input is not a WebElement"
filter_input.send_keys("abcde")
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)
exit(1)
print("The reports have been filtered", flush=True)
log_info("✅ Reports page tests finished successfully")
except SystemExit as e:
exit_code = e.code
except KeyboardInterrupt:
exit_code = 1
except:
log_exception("Something went wrong, exiting ...")
DRIVER.save_screenshot("error.png")
exit_code = 1
finally:
DRIVER.quit()
exit(exit_code)