add filter testing

This commit is contained in:
Jordan Blasenhauer 2024-02-24 23:11:47 +01:00
parent 9e546afa34
commit 5d84aea801
5 changed files with 94 additions and 9 deletions

View file

@ -7,7 +7,7 @@ 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
from utils import access_page, assert_button_click, safe_get_element, verify_select_filters
exit_code = 0
@ -68,6 +68,30 @@ try:
log_error("The bans are present but there should be 2, exiting ...")
exit(1)
log_info("Bans found, trying filters ...")
# Get total bans
bans = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-bans-list-item]")')
bans_total = len(bans)
key_word_filter_input = safe_get_element(DRIVER, "js", 'document.querySelector("input#keyword")')
assert isinstance(key_word_filter_input, WebElement), "Key word filter input is not a WebElement"
key_word_filter_input.send_keys("dzq841czqdeqzzd")
bans_hidden = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-bans-list-item][class*=hidden]")')
if len(bans_hidden) == 0:
log_error("The keyword filter is not working, exiting ...")
exit(1)
# Reset
key_word_filter_input.send_keys("")
# Test select filters
select_filters = [{"name": "reason", "id": "reason", "value": "all", "update_value": "123456"}, {"name": "range", "id": "term", "value": "all", "update_value": "123456"}]
verify_select_filters(DRIVER, "bans", select_filters)
log_info("Bans found, trying to delete them ...")
assert_button_click(DRIVER, "//input[@id='ban-item-2']")

View file

@ -7,7 +7,7 @@ from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import TimeoutException
from wizard import DRIVER, UI_URL
from utils import access_page, assert_button_click, safe_get_element
from utils import access_page, assert_button_click, safe_get_element, verify_select_filters
exit_code = 0
@ -37,6 +37,14 @@ try:
filter_input.clear()
# Test select filters
select_filters = [
{"name": "Success state", "id": "success", "value": "all", "update_value": "123456"},
{"name": "Reload state", "id": "reload", "value": "all", "update_value": "123456"},
]
verify_select_filters(DRIVER, "jobs", select_filters)
log_info("Keyword filter is working, trying to filter by success state ...")
assert_button_click(DRIVER, "//button[@data-jobs-setting-select='success']")

View file

@ -34,17 +34,37 @@ try:
log_info("Trying to filter the plugins ...")
key_word_filter_input = safe_get_element(DRIVER, By.XPATH, "//input[@placeholder='key words']")
# Get total plugins
plugins = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-plugins-type]")')
plugins_total = len(plugins)
key_word_filter_input = safe_get_element(DRIVER, "js", 'document.querySelector("input#keyword")')
assert isinstance(key_word_filter_input, WebElement), "Key word filter input is not a WebElement"
key_word_filter_input.send_keys("Anti")
key_word_filter_input.send_keys("Antibot")
plugins = safe_get_element(DRIVER, By.XPATH, "//div[@data-plugins-list='']", multiple=True)
assert isinstance(plugins, list), "Plugins list is not a list"
plugins_hidden = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-plugins-type][class*=hidden]")')
if len(plugins) != 1:
log_error("The filter is not working, exiting ...")
if len(plugins_hidden) == 0:
log_error("The keyword filter is not working, exiting ...")
exit(1)
# Reset
key_word_filter_input.send_keys("")
# Try plugin type with external
type_external_filter_input = safe_get_element(DRIVER, "js", "document.querySelector('[data-plugins-setting-select-dropdown-btn=types][value=external]')")
type_external_filter_input.click()
# At least core need to be hidden
plugins_hidden = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-plugins-type][class*=hidden]")')
if len(plugins_hidden) == 0:
log_error("The type filter is not working, exiting ...")
exit(1)
# Reset
type_all_filter_input = safe_get_element(DRIVER, "js", "document.querySelector('[data-plugins-setting-select-dropdown-btn=types][value=all]')")
type_all_filter_input.click()
log_info("The filter is working, trying to add a bad plugin ...")
file_input = safe_get_element(DRIVER, By.XPATH, "//input[@type='file' and @name='file']")

View file

@ -8,7 +8,7 @@ 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
from utils import access_page, safe_get_element, verify_select_filters
exit_code = 0
@ -30,6 +30,16 @@ try:
log_info("Trying to filter the reports ...")
# Test select filters
select_filters = [
{"name": "Country", "id": "country", "value": "all", "update_value": "123456"},
{"name": "Method", "id": "method", "value": "all", "update_value": "123456"},
{"name": "Status code", "id": "status", "value": "all", "update_value": "123456"},
{"name": "Reason", "id": "reason", "value": "all", "update_value": "123456"},
]
verify_select_filters(DRIVER, "reports", select_filters)
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"

View file

@ -157,3 +157,26 @@ def wait_for_service(service: str = "www.example.com"):
retries += 1
log_warning(f"Waiting for {service} to be ready, retrying in 5s ...")
sleep(5)
# We replace value by non existing one and click on button
# If elements are hidden, it means script is working
# Example filter_items: [ {"name" : "Success state", "id" : "success", "value" : "all", "update_value" : "123456"}]
def verify_select_filters(driver, page_name: str, filter_items: list):
for item in filter_items:
# Update in order to get no match
driver.execute_script(f"document.querySelector('[data-{page_name}-setting-select-dropdown-btn={item['id']}][value={item['value']}]').setAttribute('value', '{item['update_value']}')")
select_btn = safe_get_element(driver, "js", f"document.querySelector('[data-{page_name}-setting-select-dropdown-btn={item['id']}][value={item['update_value']}]')")
select_btn.click()
# Verify
bans_hidden = safe_get_element(driver, "js", f'document.querySelectorAll("[data-{page_name}-list-item][class*=hidden]")')
if len(bans_hidden) == 0:
log_error(f"The {item['name']} filter is not working, exiting ...")
exit(1)
# Reset
driver.execute_script(f"document.querySelector('[data-{page_name}-setting-select-dropdown-btn={item['id']}][value={item['update_value']}]').setAttribute('value', '{item['value']}')")
select_btn = safe_get_element(driver, "js", f"document.querySelector('[data-{page_name}-setting-select-dropdown-btn={item['id']}][value={item['value']}]')")
select_btn.click()
sleep(0.1)