setup_preview.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. """Open the My Services dashboard for the systemd control panel solution."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. def _wait_for_dashboard(driver, timeout=30):
  7. WebDriverWait(driver, timeout).until(
  8. lambda d: d.execute_script("return !!window.client")
  9. )
  10. WebDriverWait(driver, timeout).until(
  11. lambda d: bool(d.find_element(By.TAG_NAME, "body").get_attribute("loaded-dashboard"))
  12. )
  13. def _wait_for_my_services_dashboard(driver, timeout=30):
  14. def ready(d):
  15. required_titles = [
  16. "Start boot.mount",
  17. "Stop boot.mount",
  18. "Start podman.service",
  19. "Start upsilon-drone.service",
  20. ]
  21. for title in required_titles:
  22. try:
  23. button = d.find_element(By.CSS_SELECTOR, f'[title="{title}"]')
  24. except Exception:
  25. return False
  26. if not button.is_displayed():
  27. return False
  28. return True
  29. WebDriverWait(driver, timeout).until(ready)
  30. def run(driver):
  31. _wait_for_dashboard(driver)
  32. _wait_for_my_services_dashboard(driver)
  33. time.sleep(0.2)