setup_diagnostics.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. """Open the diagnostics page from advanced_configuration/diagnostics.adoc."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. def _wait_for_diagnostics_page(driver, timeout=30):
  7. WebDriverWait(driver, timeout).until(
  8. lambda d: d.execute_script("return !!window.client")
  9. )
  10. def ready(d):
  11. try:
  12. ssh_heading = d.find_element(
  13. By.XPATH,
  14. '//*[self::h2 or self::h3][contains(normalize-space(), "SSH")]',
  15. )
  16. server_diagnostics_heading = d.find_element(
  17. By.XPATH,
  18. '//*[self::h2 or self::h3][contains(normalize-space(), "Server Diagnostics")]',
  19. )
  20. key_value = d.find_element(
  21. By.XPATH,
  22. '//dt[contains(normalize-space(), "Found Key")]/following-sibling::dd[1]',
  23. )
  24. config_value = d.find_element(
  25. By.XPATH,
  26. '//dt[contains(normalize-space(), "Found Config")]/following-sibling::dd[1]',
  27. )
  28. except Exception:
  29. return False
  30. return all(
  31. element.is_displayed()
  32. for element in (
  33. ssh_heading,
  34. server_diagnostics_heading,
  35. key_value,
  36. config_value,
  37. )
  38. ) and all(
  39. element.text.strip() not in ("", "?")
  40. for element in (key_value, config_value)
  41. )
  42. WebDriverWait(driver, timeout).until(ready)
  43. def run(driver):
  44. _wait_for_diagnostics_page(driver)
  45. time.sleep(0.2)