mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Add UI tests for bans page
This commit is contained in:
parent
36c157d4be
commit
0609f87525
1 changed files with 101 additions and 0 deletions
101
tests/ui/bans_page.py
Normal file
101
tests/ui/bans_page.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
from contextlib import suppress
|
||||
from logging import info as log_info, exception as log_exception, error as log_error
|
||||
from random import randint
|
||||
|
||||
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, assert_button_click, safe_get_element
|
||||
|
||||
exit_code = 0
|
||||
|
||||
try:
|
||||
log_info("Navigating to the bans page ...")
|
||||
access_page(DRIVER, "/html/body/aside[1]/div[1]/div[3]/ul/li[9]/a", "bans")
|
||||
|
||||
try:
|
||||
safe_get_element(DRIVER, By.XPATH, "/html/body/main/div/div[2]/div/h5", error=True)
|
||||
except TimeoutException:
|
||||
log_exception("Bans present even though they shouldn't be, exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("No bans found, as expected, trying to add a ban ...")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-add-ban='']")
|
||||
|
||||
try:
|
||||
safe_get_element(DRIVER, By.XPATH, "//ul[@data-bans-add-ban-list='']/li", error=True)
|
||||
except TimeoutException:
|
||||
log_exception("No bans found, exiting ...")
|
||||
exit(1)
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-add-ban-delete-all-item='']")
|
||||
|
||||
with suppress(TimeoutException):
|
||||
safe_get_element(DRIVER, By.XPATH, "//ul[@data-bans-add-ban-list='']/li", error=True)
|
||||
log_error("Bans present even though they shouldn't be, exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("No bans found, as expected, trying to add multiple bans ...")
|
||||
|
||||
add_entry_button = safe_get_element(DRIVER, By.XPATH, "//button[@data-ban-add-new='']")
|
||||
assert isinstance(add_entry_button, WebElement), "Add entry button not found"
|
||||
|
||||
assert_button_click(DRIVER, add_entry_button)
|
||||
|
||||
ip_input = safe_get_element(DRIVER, By.ID, "ip-1")
|
||||
assert isinstance(ip_input, WebElement), "IP input not found"
|
||||
ip_input.send_keys(f"127.0.0.{randint(10, 122)}")
|
||||
|
||||
assert_button_click(DRIVER, add_entry_button)
|
||||
|
||||
ip_input = safe_get_element(DRIVER, By.ID, "ip-2")
|
||||
assert isinstance(ip_input, WebElement), "IP input not found"
|
||||
ip_input.send_keys(f"127.0.0.{randint(123, 255)}")
|
||||
|
||||
access_page(DRIVER, "//button[@data-bans-modal-submit='']", "bans", False)
|
||||
|
||||
try:
|
||||
entries = safe_get_element(DRIVER, By.XPATH, "//ul[@data-bans-list='']/li", multiple=True, error=True)
|
||||
assert isinstance(entries, list), "Bans not found"
|
||||
except TimeoutException:
|
||||
log_exception("No ban found, exiting ...")
|
||||
exit(1)
|
||||
|
||||
if len(entries) != 2:
|
||||
log_error("The bans are present but there should be 2, exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Bans found, trying to delete them ...")
|
||||
|
||||
assert_button_click(DRIVER, "//input[@id='ban-item-2']")
|
||||
|
||||
access_page(DRIVER, "//button[@data-unban-btn='']", "bans", False)
|
||||
|
||||
try:
|
||||
entries = safe_get_element(DRIVER, By.XPATH, "//ul[@data-bans-list='']/li", multiple=True, error=True)
|
||||
assert isinstance(entries, list), "Bans not found"
|
||||
except TimeoutException:
|
||||
log_exception("No bans found, exiting ...")
|
||||
exit(1)
|
||||
|
||||
if len(entries) != 1:
|
||||
log_error("The bans are present but there should be 1, exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Ban deleted successfully")
|
||||
|
||||
log_info("✅ Bans 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)
|
||||
Loading…
Reference in a new issue