setup_execution_dialog.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. """Open the execution-dialog view for Check dmesg logs."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. def _wait_for_body_attr(driver, attr, timeout=15):
  7. WebDriverWait(driver, timeout).until(
  8. lambda d: bool(d.find_element(By.TAG_NAME, "body").get_attribute(attr))
  9. )
  10. def _wait_for_logs_page(driver, timeout=15):
  11. WebDriverWait(driver, timeout).until(
  12. lambda d: "/logs/" in d.current_url and not d.current_url.rstrip("/").endswith("/logs")
  13. )
  14. def _wait_for_execution_complete(driver, timeout=15):
  15. def finished(d):
  16. try:
  17. status = d.find_element(By.CSS_SELECTOR, ".execution-dialog-status").text
  18. except Exception:
  19. return False
  20. return "Still running" not in status and "Queued" not in status
  21. WebDriverWait(driver, timeout).until(finished)
  22. def run(driver):
  23. _wait_for_body_attr(driver, "loaded-dashboard")
  24. driver.find_element(By.CSS_SELECTOR, '[title="Check dmesg logs"]').click()
  25. _wait_for_logs_page(driver)
  26. _wait_for_execution_complete(driver)
  27. WebDriverWait(driver, 15).until(
  28. lambda d: d.find_element(By.CSS_SELECTOR, "#execution-results-popup .xterm-rows").text.strip() != ""
  29. )
  30. time.sleep(0.2)