setup_topbar.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """Capture the topbar section navigation style."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. def _wait_for_topbar_navigation(driver, timeout=30):
  7. WebDriverWait(driver, timeout).until(
  8. lambda d: bool(d.find_element(By.TAG_NAME, "body").get_attribute("loaded-dashboard"))
  9. )
  10. def ready(d):
  11. try:
  12. topbar = d.find_element(By.CSS_SELECTOR, "nav.topbar")
  13. my_servers = d.find_element(
  14. By.XPATH,
  15. '//nav[contains(@class, "topbar")]//a[contains(normalize-space(), "My Servers")]',
  16. )
  17. my_containers = d.find_element(
  18. By.XPATH,
  19. '//nav[contains(@class, "topbar")]//a[contains(normalize-space(), "My Containers")]',
  20. )
  21. diagnostics = d.find_element(
  22. By.XPATH,
  23. '//nav[contains(@class, "topbar")]//a[contains(normalize-space(), "Diagnostics")]',
  24. )
  25. logs = d.find_element(
  26. By.XPATH,
  27. '//nav[contains(@class, "topbar")]//a[contains(normalize-space(), "Logs")]',
  28. )
  29. ping_host = d.find_element(By.CSS_SELECTOR, '[title="Ping host"]')
  30. restart = d.find_element(By.CSS_SELECTOR, '[title="Restart Docker Container"]')
  31. delete_backups = d.find_element(By.CSS_SELECTOR, '[title="Delete old backups"]')
  32. except Exception:
  33. return False
  34. return topbar.is_displayed() and all(
  35. element.is_displayed()
  36. for element in (
  37. my_servers,
  38. my_containers,
  39. diagnostics,
  40. logs,
  41. ping_host,
  42. restart,
  43. delete_backups,
  44. )
  45. )
  46. WebDriverWait(driver, timeout).until(ready)
  47. def run(driver):
  48. _wait_for_topbar_navigation(driver)
  49. time.sleep(0.2)