Fix instance stop functionality tests

This commit is contained in:
Théophile Diot 2024-03-24 11:06:51 +00:00
parent a9d05552dd
commit 31f65bf67d
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06

View file

@ -1,11 +1,11 @@
from logging import info as log_info, exception as log_exception, warning as log_warning
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import TimeoutException, WebDriverException
from wizard import DRIVER
from base import TEST_TYPE
from utils import access_page, assert_alert_message, safe_get_element, wait_for_service
from utils import access_page, assert_button_click, safe_get_element, wait_for_service
exit_code = 0
@ -40,30 +40,16 @@ try:
log_info("Trying to stop instance ...")
no_errors = True
retries = 0
action = "stop"
while no_errors:
log_info(f"Trying to {action} BunkerWeb instance ...")
log_info(f"Trying to {action} BunkerWeb instance ...")
try:
form = safe_get_element(DRIVER, By.XPATH, "//form[starts-with(@id, 'form-instance-')]")
except TimeoutException:
log_exception("No instance form found, exiting ...")
exit(1)
try:
access_page(DRIVER, f"//form[starts-with(@id, 'form-instance-')]//button[@value='{action}']", "instances", False)
log_info(f"Instance was {action}ed successfully ...")
no_errors = False
except:
if retries >= 3:
exit(1)
retries += 1
log_warning("Error while stopping instance, retrying...")
if TEST_TYPE == "linux":
wait_for_service()
try:
assert_button_click(DRIVER, f"//form[starts-with(@id, 'form-instance-')]//button[@value='{action}']")
safe_get_element(DRIVER, By.XPATH, "//form[starts-with(@id, 'form-instance-')]")
log_exception("Instance was not stopped successfully, exiting ...")
exit(1)
except (TimeoutException, WebDriverException):
log_info(f"Instance was {action}ed successfully ...")
log_info("✅ Instances page tests finished successfully")
except SystemExit as e: