mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
update ui tests
* enhance bans page test : toggle modal + better filter testing * enhance global config page test : select plugin + test every setting type + better filter * enhance services page test : modal test + one plugin a time + better modal filter + modal settings type + update services card filter * add return keyword on execute_script
This commit is contained in:
parent
bd07f573d3
commit
ced2428eed
9 changed files with 219 additions and 74 deletions
|
|
@ -37,7 +37,7 @@ try:
|
|||
|
||||
log_info("username 'admin' is correctly set by default, trying username update ...")
|
||||
|
||||
DRIVER.execute_script(f"arguments[0].value = 'admin2'", username_input)
|
||||
DRIVER.execute_script(f"return arguments[0].value = 'admin2'", username_input)
|
||||
|
||||
password_input = safe_get_element(DRIVER, By.ID, "curr_password")
|
||||
assert isinstance(password_input, WebElement), "The password input is not an instance of WebElement"
|
||||
|
|
@ -47,7 +47,7 @@ try:
|
|||
exit(1)
|
||||
|
||||
# execute script using create password_input
|
||||
DRIVER.execute_script(f"arguments[0].value = '{UI_PASSWORD}'", password_input)
|
||||
DRIVER.execute_script(f"return arguments[0].value = '{UI_PASSWORD}'", password_input)
|
||||
assert_button_click(DRIVER, "//button[@id='username-button' and @class='edit-btn']")
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -54,7 +54,14 @@ try:
|
|||
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 ...")
|
||||
log_info("Toggle modal, then trying to add multiple bans ...")
|
||||
|
||||
close_modal = safe_get_element(DRIVER, By.XPATH, "//button[@data-bans-modal-close='']")
|
||||
assert isinstance(close_modal, WebElement), "Add entry button not found"
|
||||
|
||||
assert_button_click(DRIVER, close_modal)
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-add-ban='']")
|
||||
|
||||
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"
|
||||
|
|
@ -62,14 +69,16 @@ try:
|
|||
assert_button_click(DRIVER, add_entry_button)
|
||||
|
||||
ip_input = safe_get_element(DRIVER, By.ID, "ip-2")
|
||||
ip_input_value = f"127.0.0.{randint(10, 122)}"
|
||||
assert isinstance(ip_input, WebElement), "IP input not found"
|
||||
ip_input.send_keys(f"127.0.0.{randint(10, 122)}")
|
||||
ip_input.send_keys(ip_input_value)
|
||||
|
||||
assert_button_click(DRIVER, add_entry_button)
|
||||
|
||||
ip_input = safe_get_element(DRIVER, By.ID, "ip-3")
|
||||
assert isinstance(ip_input, WebElement), "IP input not found"
|
||||
ip_input.send_keys(f"127.0.0.{randint(123, 255)}")
|
||||
ip_input_2 = safe_get_element(DRIVER, By.ID, "ip-3")
|
||||
ip_input_value_2 = f"127.0.0.{randint(123, 255)}"
|
||||
assert isinstance(ip_input_2, WebElement), "IP input not found"
|
||||
ip_input_2.send_keys(ip_input_value_2)
|
||||
|
||||
log_info("Added 2 bans entries to modal, click on save ...")
|
||||
|
||||
|
|
@ -86,6 +95,53 @@ try:
|
|||
log_error("The bans are present but there should be 2, exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Bans added successfully, trying to filter ...")
|
||||
|
||||
# Get total bans
|
||||
bans = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-bans-list-item]")')
|
||||
bans_total = len(bans)
|
||||
|
||||
if bans_total == 0:
|
||||
log_error("Need at least one ban to test filters ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Start with keyword filtering ...")
|
||||
|
||||
key_word_filter_input = safe_get_element(DRIVER, By.XPATH, "//input[@id='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]")')
|
||||
bans_hidden_total = len(bans_hidden)
|
||||
|
||||
log_info(f"Added 'dzq841czqdeqzzd' value, bans hidden {bans_hidden_total} / {bans_total} ...")
|
||||
|
||||
if bans_hidden_total != 2:
|
||||
log_error("Keyword filtering error, should have match nothing ...")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
key_word_filter_input.send_keys(Keys.CONTROL, "a")
|
||||
key_word_filter_input.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Keyword filter with no match worked, trying to match a ban value ...")
|
||||
key_word_filter_input.send_keys(ip_input_value_2)
|
||||
|
||||
bans_hidden = safe_get_element(DRIVER, "js", 'document.querySelectorAll("[data-bans-list-item][class*=hidden]")')
|
||||
bans_hidden_total = len(bans_hidden)
|
||||
|
||||
if bans_hidden_total != 1:
|
||||
log_error("Keyword filtering error, should have match one ban ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Keyword filter to show only one ban worked, trying select filters ...")
|
||||
|
||||
# Test select filters
|
||||
select_filters = [{"name": "reason", "id": "reason", "value": "all"}, {"name": "range", "id": "term", "value": "all"}]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-bans-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("Trying to delete 1 ban ...")
|
||||
|
||||
try:
|
||||
|
|
@ -133,43 +189,6 @@ try:
|
|||
log_error("The bans are present but there should be 1, 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)
|
||||
|
||||
if bans_total == 0:
|
||||
log_error("Need at least one ban to test filters ...")
|
||||
exit(1)
|
||||
|
||||
log_info("Start with keyword filtering ...")
|
||||
|
||||
key_word_filter_input = safe_get_element(DRIVER, By.XPATH, "//input[@id='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]")')
|
||||
bans_hidden_total = len(bans_hidden)
|
||||
|
||||
log_info(f"Added 'dzq841czqdeqzzd' value, bans hidden {bans_hidden_total} / {bans_total} ...")
|
||||
|
||||
if bans_hidden_total != 1:
|
||||
log_error("Keyword filtering error, should have match nothing ...")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
key_word_filter_input.send_keys(Keys.CONTROL, "a")
|
||||
key_word_filter_input.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Keyword filter worked, trying select filters ...")
|
||||
|
||||
# Test select filters
|
||||
select_filters = [{"name": "reason", "id": "reason", "value": "all"}, {"name": "range", "id": "term", "value": "all"}]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-bans-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("Ban deleted successfully")
|
||||
|
||||
log_info("✅ Bans page tests finished successfully")
|
||||
|
|
|
|||
|
|
@ -18,22 +18,60 @@ try:
|
|||
log_info("Trying filters ...")
|
||||
|
||||
# Set keyword with no matching settings
|
||||
keyword_no_match = "dqz48 é84 dzq 584dz5qd4"
|
||||
btn_keyword = safe_get_element(DRIVER, "js", 'document.querySelector("input#keyword")')
|
||||
btn_keyword.send_keys(keyword_no_match)
|
||||
sleep(0.1)
|
||||
input_keyword = safe_get_element(DRIVER, By.ID, "keyword")
|
||||
input_keyword.send_keys("dqz48 é84 dzq 584dz5qd4")
|
||||
|
||||
# Check that the no matching element is shown and other card hide
|
||||
is_no_match = DRIVER.execute_script('return !document.querySelector("[data-global-config-nomatch]").classList.contains("hidden")')
|
||||
if not is_no_match:
|
||||
log_error(f"Filter keyword with value {keyword_no_match} shouldn't match something.")
|
||||
is_no_match_hidden = DRIVER.execute_script('return document.querySelector("[data-global-config-nomatch]").classList.contains("hidden")')
|
||||
|
||||
if is_no_match_hidden:
|
||||
log_error(f"Filter keyword shouldn't match something.")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
btn_keyword.send_keys(Keys.CONTROL, "a")
|
||||
btn_keyword.send_keys(Keys.BACKSPACE)
|
||||
input_keyword.send_keys(Keys.CONTROL, "a")
|
||||
input_keyword.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Filter with unmatched keyword works as expected, try with a keyword that matches a setting...")
|
||||
log_info("Filter with unmatched keyword works as expected, try to match a setting ...")
|
||||
|
||||
input_keyword.send_keys("http port")
|
||||
|
||||
# Check that the matching element is shown and other card hide
|
||||
is_http_port_hidden = DRIVER.execute_script(f"""return document.querySelector('#form-edit-global-config-http-port').classList.contains('hidden')""")
|
||||
|
||||
if is_http_port_hidden:
|
||||
log_error(f"hidden http port should be match.")
|
||||
exit(1)
|
||||
|
||||
is_https_port_hidden = DRIVER.execute_script(f"""return document.querySelector('#form-edit-global-config-https-port').classList.contains('hidden')""")
|
||||
|
||||
if not is_https_port_hidden:
|
||||
log_error(f"Setting https port should not be match.")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
input_keyword.send_keys(Keys.CONTROL, "a")
|
||||
input_keyword.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Matching a setting done ...")
|
||||
|
||||
log_info("Filters working, trying settings interaction ...")
|
||||
|
||||
log_info("Select from dropdown ...")
|
||||
|
||||
select = safe_get_element(DRIVER, By.XPATH, "//button[@data-setting-select='timers-log-level']")
|
||||
assert_button_click(DRIVER, select)
|
||||
|
||||
select_active_item = safe_get_element(DRIVER, By.XPATH, "//button[@data-setting-select-dropdown-btn='timers-log-level' and contains(@class, 'active')]")
|
||||
assert_button_click(DRIVER, select_active_item)
|
||||
|
||||
log_info("Select dropdown done, trying toggle checkbox...")
|
||||
|
||||
checkbox_api = safe_get_element(DRIVER, By.ID, "USE_API")
|
||||
assert_button_click(DRIVER, checkbox_api)
|
||||
assert_button_click(DRIVER, checkbox_api)
|
||||
|
||||
log_info("Toggle checkbox done, trying to update global config ...")
|
||||
|
||||
no_errors = True
|
||||
retries = 0
|
||||
|
|
@ -98,10 +136,15 @@ try:
|
|||
log_error(f"The value was not updated ({input_worker.get_attribute('value')} instead of 4096), exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info("The value was updated successfully, trying to select another plugin ...")
|
||||
log_info("The value was updated successfully, trying to select all plugins ...")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-tab-select-dropdown-btn='']")
|
||||
assert_button_click(DRIVER, "//button[@data-tab-select-handler='blacklist']")
|
||||
# Open dropdown to select all plugins and click on them
|
||||
buttons_plugin = DRIVER.execute_script('return document.querySelectorAll("button[data-tab-select-handler]")')
|
||||
|
||||
for button in buttons_plugin:
|
||||
DRIVER.execute_script("arguments[0].click()", button)
|
||||
|
||||
log_info("Selecting all plugins worked ...")
|
||||
|
||||
log_info("✅ Global config page tests finished successfully")
|
||||
except SystemExit as e:
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ try:
|
|||
]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-jobs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-jobs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("Keyword filter is working, trying to filter by success state ...")
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ try:
|
|||
]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-logs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-logs-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("Selecting correct instance ...")
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ try:
|
|||
]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-plugins-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-plugins-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("The filter is working, trying to add a bad plugin ...")
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ try:
|
|||
]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-reports-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-reports-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
filter_input = safe_get_element(DRIVER, By.ID, "keyword")
|
||||
assert isinstance(filter_input, WebElement), "Keyword filter input is not a WebElement"
|
||||
|
|
|
|||
|
|
@ -57,8 +57,94 @@ try:
|
|||
|
||||
log_info("Input service checked ...")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-services-modal-close='']")
|
||||
assert_button_click(DRIVER, "//button[@data-services-action='new']")
|
||||
|
||||
log_info("Toggle modal checked, trying settings ...")
|
||||
|
||||
log_info("Check only one plugin is visible ...")
|
||||
|
||||
is_general_plugin_hidden = DRIVER.execute_script(f"""return document.querySelector('[data-plugin-item="general"]').classList.contains('hidden')""")
|
||||
|
||||
if is_general_plugin_hidden:
|
||||
log_error(f"Plugin general should be visible.")
|
||||
exit(1)
|
||||
|
||||
is_antibot_plugin_hidden = DRIVER.execute_script(f"""return document.querySelector('[data-plugin-item="antibot"]').classList.contains('hidden')""")
|
||||
|
||||
if not is_antibot_plugin_hidden:
|
||||
log_error(f"Plugin antibot should not be visible.")
|
||||
exit(1)
|
||||
|
||||
log_info("Only one plugin visible checked, trying keyword no match ...")
|
||||
|
||||
# Set keyword with no matching settings
|
||||
input_keyword = safe_get_element(DRIVER, By.ID, "settings-filter")
|
||||
input_keyword.send_keys("dqz48 é84 dzq 584dz5qd4")
|
||||
|
||||
# Check that the no matching element is shown and other card hide
|
||||
is_no_match = DRIVER.execute_script('return document.querySelector("[data-services-nomatch]").classList.contains("hidden")')
|
||||
if is_no_match:
|
||||
log_error(f"Filter keyword shouldn't match something.")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
input_keyword.send_keys(Keys.CONTROL, "a")
|
||||
input_keyword.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Filter with unmatched keyword works as expected, try to match a setting ...")
|
||||
|
||||
input_keyword.send_keys("server type")
|
||||
|
||||
# Check that the matching element is shown and other card hide
|
||||
is_server_type_hidden = DRIVER.execute_script(f"""return document.querySelector('#form-edit-services-server-type').classList.contains('hidden')""")
|
||||
|
||||
if is_server_type_hidden:
|
||||
log_error(f"Setting server type should be match.")
|
||||
exit(1)
|
||||
|
||||
is_server_name_hidden = DRIVER.execute_script(f"""return document.querySelector('#form-edit-services-server-name').classList.contains('hidden')""")
|
||||
|
||||
if not is_server_name_hidden:
|
||||
log_error(f"Setting server name should not be match.")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
input_keyword.send_keys(Keys.CONTROL, "a")
|
||||
input_keyword.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Matching a setting done, trying select dropdown ...")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-tab-select-dropdown-btn='']")
|
||||
|
||||
select = safe_get_element(DRIVER, By.XPATH, "//button[@data-setting-select='server-type']")
|
||||
assert_button_click(DRIVER, select)
|
||||
|
||||
select_active_item = safe_get_element(DRIVER, By.XPATH, "//button[@data-setting-select-dropdown-btn='server-type' and contains(@class, 'active')]")
|
||||
assert_button_click(DRIVER, select_active_item)
|
||||
|
||||
log_info("Select dropdown done, trying toggle checkbox...")
|
||||
|
||||
checkbox_api = safe_get_element(DRIVER, By.ID, "LISTEN_STREAM")
|
||||
assert_button_click(DRIVER, checkbox_api)
|
||||
assert_button_click(DRIVER, checkbox_api)
|
||||
|
||||
log_info("Toggle checkbox done, trying multiple plugins select ...")
|
||||
|
||||
# Open dropdown to select all plugins and click on them
|
||||
buttons_plugin = DRIVER.execute_script('return document.querySelectorAll("button[data-tab-select-handler]")')
|
||||
|
||||
for button in buttons_plugin:
|
||||
DRIVER.execute_script("arguments[0].click()", button)
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-services-modal-close='']")
|
||||
|
||||
log_info("Multiple plugins select done ...")
|
||||
|
||||
log_info("Additional checks done, trying to edit the config ...")
|
||||
|
||||
assert_button_click(DRIVER, "//div[@data-services-service='www.example.com']//button[@data-services-action='edit']")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-tab-select-dropdown-btn='']")
|
||||
assert_button_click(DRIVER, "//button[@data-tab-select-handler='gzip']")
|
||||
gzip_select = safe_get_element(DRIVER, By.XPATH, "//button[@data-setting-select='gzip-comp-level']")
|
||||
|
|
@ -93,7 +179,7 @@ try:
|
|||
|
||||
assert_button_click(DRIVER, "//button[@data-services-modal-close='']/*[local-name() = 'svg']")
|
||||
|
||||
log_info("Creating a new service ...")
|
||||
log_info("Setting updated, creating a new service ...")
|
||||
|
||||
assert_button_click(DRIVER, "//button[@data-services-action='new']")
|
||||
|
||||
|
|
@ -295,7 +381,7 @@ try:
|
|||
log_error(f"The service hasn't been created ({len(services)} services found), exiting ...")
|
||||
exit(1)
|
||||
|
||||
log_info(f"We need 4 services to test filter, currently {len(services)}")
|
||||
log_info(f"We need at least 4 services to test filter, currently {len(services)}")
|
||||
|
||||
server_name_elem = safe_get_element(DRIVER, By.XPATH, "//div[@data-services-service='app3.example.com']//h5")
|
||||
assert isinstance(server_name_elem, WebElement), "Server name element is not a WebElement"
|
||||
|
|
@ -312,20 +398,19 @@ try:
|
|||
log_info("Service app3.example.com is present, trying service card filters...")
|
||||
|
||||
# Set keyword with no matching settings
|
||||
keyword_no_match = "dqz48 é84 dzq 584dz5qd4"
|
||||
btn_keyword = safe_get_element(DRIVER, "js", 'document.querySelector("input#service-name-keyword")')
|
||||
btn_keyword.send_keys(keyword_no_match)
|
||||
input_card_keyword = safe_get_element(DRIVER, By.ID, "service-name-keyword")
|
||||
input_card_keyword.send_keys("dqz48 é84 dzq 584dz5qd4")
|
||||
sleep(0.1)
|
||||
|
||||
# Check that the no matching element is shown and other card hide
|
||||
is_no_match = DRIVER.execute_script('return document.querySelector("[data-services-nomatch-card]").classList.contains("hidden") ? false : true')
|
||||
if not is_no_match:
|
||||
log_error(f"Filter keyword with value {keyword_no_match} shouldn't match something.")
|
||||
is_no_match = DRIVER.execute_script('return document.querySelector("[data-services-nomatch-card]").classList.contains("hidden")')
|
||||
if is_no_match:
|
||||
log_error(f"Filter keyword shouldn't match something.")
|
||||
exit(1)
|
||||
|
||||
# Reset
|
||||
btn_keyword.send_keys(Keys.CONTROL, "a")
|
||||
btn_keyword.send_keys(Keys.BACKSPACE)
|
||||
input_card_keyword.send_keys(Keys.CONTROL, "a")
|
||||
input_card_keyword.send_keys(Keys.BACKSPACE)
|
||||
|
||||
log_info("Service card keyword filter working, trying select filters ...")
|
||||
|
||||
|
|
@ -336,7 +421,7 @@ try:
|
|||
]
|
||||
|
||||
for item in select_filters:
|
||||
DRIVER.execute_script(f"""document.querySelector('[data-services-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
DRIVER.execute_script(f"""return document.querySelector('[data-services-setting-select-dropdown-btn="{item["id"]}"][value="{item["value"]}"]').click()""")
|
||||
|
||||
log_info("Filters working as expected, trying to delete app3.example.com ...")
|
||||
|
||||
|
|
|
|||
|
|
@ -140,8 +140,6 @@ def access_page(driver, button: Union[bool, str, WebElement], name: str, message
|
|||
log_info(f"{name.title()} page loaded successfully")
|
||||
|
||||
driver.set_window_size(2560, 1440)
|
||||
log_info("Try update window size to 2560,1440")
|
||||
log_info("Current window size is: " + str(driver.get_window_size()))
|
||||
|
||||
|
||||
def wait_for_service(service: str = "www.example.com"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue