0
0
Fork 0
mirror of https://github.com/nextcloud/docker.git synced 2025-04-19 18:36:09 +02:00
nextcloud-docker/energy-tests/helpers/helper_functions.py
2024-10-15 14:51:56 +02:00

30 lines
986 B
Python

import random
from time import time_ns, sleep
from playwright.sync_api import TimeoutError
def login(page, username='Crash', password='Override'):
page.goto("http://nc/login")
page.locator('#user').fill(username)
page.locator('#password').fill(password)
page.locator('#password').press("Enter")
def get_random_text() -> str:
size_in_bytes = 1024
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(size_in_bytes))
def log_note(message: str) -> None:
timestamp = str(time_ns())[:16]
print(f"{timestamp} {message}")
def close_modal(page) -> None:
with contextlib.suppress(TimeoutError):
sleep(5) # Sleep to make sure the modal has time to appear before continuing navigation
page.locator('#firstrunwizard .modal-container__content button[aria-label=Close]', timeout=15_000).click()
def timeout_handler(signum, frame):
raise TimeoutError("Page.content() timed out")