Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dashboard automation support #4249

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ceph/UI/browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from selenium import webdriver


class Browser:
def __init__(self, browser_type: str = "chrome"):
"""
Initializes the Browser with the specified browser type.
:param browser_type: The type of browser to use ('chrome', 'firefox', etc.). Defaults to 'chrome'.
"""
if browser_type.lower() == "chrome":
self.driver = webdriver.Chrome()
elif browser_type.lower() == "firefox":
self.driver = webdriver.Firefox()
else:
raise ValueError(
f"Unsupported browser type: {browser_type}. Supported types are 'chrome' and 'firefox'."
)
41 changes: 41 additions & 0 deletions ceph/UI/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from selenium.webdriver.support import expected_conditions as EC

# from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

from ceph.UI.browser import Browser

# from selenium.common.exceptions import TimeoutException
from ceph.UI.ids import ElementIDs


class Dashboard:
def __init__(self, browser_type: str = "chrome"):
self.browser = Browser(browser_type)
self.driver = self.browser.driver
self.element_ids = None # ElementIDs instance will be set dynamically

def load_elements(self, yaml_file_path: str):
self.element_ids = ElementIDs(yaml_file_path)

def open(self, url: str):
if not isinstance(url, str):
raise ValueError("A valid URL must be provided.")
self.driver.get(url)

def is_element_visible(self, key: str, timeout: int = 10) -> bool:
element = self.find_element(key, timeout)
return element.is_displayed() if element else False

def find_element(self, key: str, timeout: int = 10):
if not self.element_ids:
raise RuntimeError("ElementIDs not loaded. Use 'load_elements' first.")
return self.element_ids.get_element(key, self.driver, timeout)

def click(self, key: str, timeout: int = 10):
element = self.find_element(key, timeout)
WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(element))
element.click()

def quit(self):
self.driver.quit()