mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-02 22:26:04 -05:00
Enhance device MAC address handling in tests to ensure lowercase normalization and skip tests when web protection is disabled
This commit is contained in:
@@ -8,6 +8,7 @@ import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
from selenium.webdriver.common.by import By
|
||||
|
||||
# Add test directory to path
|
||||
@@ -73,6 +74,16 @@ def get_login_password():
|
||||
return None
|
||||
|
||||
|
||||
def require_login_page(driver):
|
||||
"""Skip the test if the login form is not present (web protection disabled)."""
|
||||
fields = driver.find_elements(By.NAME, "loginpassword")
|
||||
if not fields:
|
||||
pytest.skip(
|
||||
"Web protection is disabled (SETPWD_enable_password != true); "
|
||||
"login page is not shown on this instance"
|
||||
)
|
||||
|
||||
|
||||
def perform_login(driver, password=None):
|
||||
"""Helper function to perform login with optional password fallback
|
||||
|
||||
@@ -83,6 +94,7 @@ def perform_login(driver, password=None):
|
||||
if password is None:
|
||||
password = "123456" # Default test password
|
||||
|
||||
require_login_page(driver)
|
||||
password_input = driver.find_element(By.NAME, "loginpassword")
|
||||
password_input.send_keys(password)
|
||||
|
||||
@@ -100,7 +112,9 @@ def test_login_page_loads(driver):
|
||||
driver.get(f"{BASE_URL}/index.php")
|
||||
wait_for_page_load(driver)
|
||||
|
||||
# Check that login form is present
|
||||
# Skip if web protection is disabled (page redirected away from login form)
|
||||
require_login_page(driver)
|
||||
|
||||
password_field = driver.find_element(By.NAME, "loginpassword")
|
||||
assert password_field, "Password field should be present"
|
||||
|
||||
@@ -230,6 +244,9 @@ def test_url_hash_hidden_input_present(driver):
|
||||
driver.get(f"{BASE_URL}/index.php")
|
||||
wait_for_page_load(driver)
|
||||
|
||||
# Skip if web protection is disabled (login form not shown)
|
||||
require_login_page(driver)
|
||||
|
||||
# Verify the hidden input field exists
|
||||
url_hash_input = driver.find_element(By.ID, "url_hash")
|
||||
assert url_hash_input, "Hidden url_hash input field should be present"
|
||||
|
||||
Reference in New Issue
Block a user