Fix ui tests (again)

This commit is contained in:
Théophile Diot 2023-05-20 17:46:55 -04:00
parent ace88d865d
commit 9b58b397c9
No known key found for this signature in database
GPG Key ID: E752C80DB72BB014
2 changed files with 20 additions and 12 deletions

View File

@ -21,7 +21,14 @@ RUN touch test.txt && \
zip test.zip test.txt && \
rm test.txt
RUN echo '{\n "id": "discord",\n "name": "Discord", \n "description": "Send alerts to a Discord channel (using webhooks).", \n "version": "0.1", \n "stream": "no", \n "settings": {}\n}' > plugin.json && \
RUN echo '{ \
"id": "discord", \
"name": "Discord", \
"description": "Send alerts to a Discord channel (using webhooks).", \
"version": "0.1", \
"stream": "no", \
"settings": {} \
}' > plugin.json && \
zip discord.zip plugin.json && \
rm plugin.json

View File

@ -49,6 +49,7 @@ if "geckodriver" not in listdir(Path.cwd()):
print("Starting Firefox ...", flush=True)
def safe_get_element(
driver, by: By, _id: str, *, multiple: bool = False, error: bool = False
) -> Union[WebElement, List[WebElement]]:
@ -62,11 +63,10 @@ def safe_get_element(
if error:
raise e
print(
f'Element searched by {by}: "{_id}" not found, exiting ...', flush=True
)
print(f'Element searched by {by}: "{_id}" not found, exiting ...', flush=True)
exit(1)
def assert_button_click(driver, button: Union[str, WebElement]):
clicked = False
while not clicked:
@ -79,6 +79,7 @@ def assert_button_click(driver, button: Union[str, WebElement]):
button.click()
clicked = True
def assert_alert_message(driver, message: str):
safe_get_element(driver, By.XPATH, "//button[@data-flash-sidebar-open='']")
@ -117,14 +118,13 @@ def assert_alert_message(driver, message: str):
)
exit(1)
print(
f'Message "{message}" found in one of the messages in the list', flush=True
)
print(f'Message "{message}" found in one of the messages in the list', flush=True)
assert_button_click(
driver, "//aside[@data-flash-sidebar='']/*[local-name() = 'svg']"
)
def access_page(
driver,
driver_wait: WebDriverWait,
@ -149,9 +149,7 @@ def access_page(
except TimeoutException:
if retries < 3 and driver.current_url.split("/")[-1].startswith("/loading"):
sleep(2)
access_page(
driver, driver_wait, button, name, message, retries=retries + 1
)
access_page(driver, driver_wait, button, name, message, retries=retries + 1)
print(f"{name.title()} page didn't load in time, exiting ...", flush=True)
exit(1)
@ -162,6 +160,7 @@ def access_page(
flush=True,
)
with webdriver.Firefox(
service=Service(
executable_path="./geckodriver"
@ -901,6 +900,8 @@ with webdriver.Firefox(
driver, By.XPATH, "//input[@type='file' and @name='file']"
).send_keys(join(Path.cwd(), "test.zip"))
sleep(2)
access_page(
driver,
driver_wait,
@ -909,8 +910,6 @@ with webdriver.Firefox(
False,
)
sleep(2)
print(
"The bad plugin has been rejected, trying to add a good plugin ...",
flush=True,
@ -920,6 +919,8 @@ with webdriver.Firefox(
driver, By.XPATH, "//input[@type='file' and @name='file']"
).send_keys(join(Path.cwd(), "discord.zip"))
sleep(2)
access_page(
driver,
driver_wait,