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

Fixing tests for new grafana version. #649

Merged
merged 6 commits into from
Oct 26, 2024
Merged
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
5 changes: 4 additions & 1 deletion tests/testflows/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def argparser(parser):
],
"/Grafana Datasource Plugin For Clickhouse/data source setup/check default values datetime64/": [
(Error, "https://github.com/Altinity/clickhouse-grafana/issues/630")
],
"/Grafana Datasource Plugin For Clickhouse/sql editor/extrapolation toggle/":[
(Fail, "Run Query button do not update time ranges")
]
}

Expand Down Expand Up @@ -109,7 +112,7 @@ def regression(self, before, after):
Feature(run=load("testflows.tests.automated.sql_editor", "feature"))
Feature(run=load("testflows.tests.automated.data_source_setup", "feature"))
Feature(run=load("testflows.tests.automated.e2e", "feature"))
Feature(run=load("testflows.tests.automated.query_settings", "feature"))
Feature(run=load("testflows.tests.automated.query_options", "feature"))
Feature(run=load("testflows.tests.automated.unified_alerts", "feature"))

self.context.grafana_version = "10.4.3"
Expand Down
7 changes: 6 additions & 1 deletion tests/testflows/steps/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def compare_screenshots(self, screenshot_name_1, screenshot_name_2):


@TestStep(Given)
def create_dashboard(self, dashboard_name, open_it=True):
def create_dashboard(self, dashboard_name, open_it=True, finally_save_dashboard=True):
"""Create new dashboard named {dashboard_name} and open it."""
try:
for attempt in retries(delay=10, timeout=120):
Expand All @@ -51,6 +51,11 @@ def create_dashboard(self, dashboard_name, open_it=True):
dashboards.open_dashboard(dashboard_name=dashboard_name)
yield
finally:
if finally_save_dashboard:
with Finally("I save changes for dashboard"):
with delay(after=0.5):
panel.save_dashboard()

with Finally(f"I delete dashboard {dashboard_name}"):
dashboards.delete_dashboard(dashboard_name=dashboard_name)

Expand Down
32 changes: 21 additions & 11 deletions tests/testflows/steps/dashboard/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,45 @@ class Locators:
# Locators for dashboard page

def panel(self, panel_name):

driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='data-testid Panel header {panel_name}']")

def menu_button_for_panel(self, panel_name):

driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='data-testid Panel menu {panel_name}']")

def edit_button_for_panel(self):

driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='data-testid Panel menu item Edit']")

@property
def save_dashboard(self):


def save_dashboard(self, grafana_version):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[aria-label='Save dashboard']")
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f"[aria-label='Save dashboard']")
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='data-testid Save dashboard button']")

@property
def save_dashboard_title(self):
def save_dashboard_title(self, grafana_version):
driver: WebDriver = current().context.driver
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f"[class ='css-8tk2dk-input-input']")
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='Save dashboard title field']")

def save_dashboard_button(self, grafana_version):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[class ='css-8tk2dk-input-input']")
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f"[class ='css-td06pi-button']")
else:
return driver.find_element(SelectBy.CSS_SELECTOR,
f"[data-testid='data-testid Save dashboard drawer button']")

@property
def save_dashboard_button(self):
def edit_button(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f"[class ='css-td06pi-button']")
return driver.find_element(SelectBy.CSS_SELECTOR, f"[data-testid='data-testid Edit dashboard button']")

@property
def add_button(self):
Expand Down
26 changes: 19 additions & 7 deletions tests/testflows/steps/dashboard/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def wait_edit_button_in_panel_menu(self):


@TestStep(When)
def click_edit_button(self):
def click_edit_button_for_panel(self):
"""Click edit button in dropdown menu for panel."""

locators.edit_button_for_panel().click()
Expand Down Expand Up @@ -82,7 +82,7 @@ def edit_panel(self, panel_name):
wait_edit_button_in_panel_menu()

with By("clicking edit button"):
click_edit_button()
click_edit_button_for_panel()


@TestStep(When)
Expand All @@ -102,21 +102,28 @@ def take_panel_screenshot(self, panel_name, screenshot_name):
@TestStep(When)
def click_save_button(self):
"""Open saving menu for dashboard."""
locators.save_dashboard.click()
locators.save_dashboard(grafana_version=self.context.grafana_version).click()


@TestStep(When)
def change_title_for_dashboard(self, dashboard_name):
"""Change title for dashboard in saving menu."""
locators.save_dashboard_title.clear()
locators.save_dashboard_title(grafana_version=self.context.grafana_version).clear()

locators.save_dashboard_title.send_keys(dashboard_name)
locators.save_dashboard_title(grafana_version=self.context.grafana_version).send_keys(dashboard_name)


@TestStep(When)
def click_save_dashboard_button(self):
"""Save dashboard."""
locators.save_dashboard_button.click()
locators.save_dashboard_button(grafana_version=self.context.grafana_version).click()


@TestStep(When)
def click_edit_button(self):
"""Click edit button."""

locators.edit_button.click()


@TestStep(When)
Expand All @@ -132,7 +139,7 @@ def saving_dashboard(self, dashboard_name=None):
change_title_for_dashboard(dashboard_name=dashboard_name)

with By("clicking save button"):
with delay():
with delay(before=0.5):
click_save_dashboard_button()


Expand Down Expand Up @@ -262,6 +269,11 @@ def open_new_dashboard_endpoint(self, endpoint=None):
def add_visualization(self):
"""Add visualization for dashboard."""

if (self.context.grafana_version is None) or (int(self.context.grafana_version.split(".")[0]) > 10):
with delay():
with By("clicking edit button"):
click_edit_button()

with delay():
with By("clicking add button"):
click_add_button()
Expand Down
6 changes: 4 additions & 2 deletions tests/testflows/steps/dashboards/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def create_new_dashboard(self):
def delete_dashboard(self, dashboard_name):
"""Delete dashboard."""
with By("opening dashboards view"):
open_dashboards_view()
with delay():
open_dashboards_view()

with By("selecting dashboard"):
with delay():
Expand All @@ -109,7 +110,8 @@ def delete_dashboard(self, dashboard_name):
enter_delete_conformation()

with By("clicking delete button in confirmation window"):
click_delete_confirmation_button()
with delay():
click_delete_confirmation_button()


@TestStep(When)
Expand Down
29 changes: 20 additions & 9 deletions tests/testflows/steps/panel/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,26 @@ def apply_button(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Apply changes and go back to dashboard"]')

@property
def save_button(self):
def save_button(self, grafana_version):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[title="Apply changes and save dashboard"]')
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f'[title="Apply changes and save dashboard"]')
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Save dashboard button"]')

@property
def save_confirmations_button(self):
def save_confirmations_button(self, grafana_version):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[aria-label="Dashboard settings Save Dashboard Modal Save button"]')
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f'[aria-label="Dashboard settings Save Dashboard Modal Save button"]')
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Save dashboard drawer button"]')

@property
def discard_button(self):
def discard_button(self, grafana_version):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[title="Undo all changes"]')
if not (grafana_version is None) and (int(grafana_version.split(".")[0]) <= 10):
return driver.find_element(SelectBy.CSS_SELECTOR, f'[title="Undo all changes"]')
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Discard changes button"]')

@property
def run_query_button(self):
Expand Down Expand Up @@ -284,5 +290,10 @@ def alert_tab(self, grafana_version=None):
else:
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Tab Alert"]')

@property
def query_inspector_close_button(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.CSS_SELECTOR, f'[data-testid="data-testid Drawer close"]')


locators = Locators()
2 changes: 1 addition & 1 deletion tests/testflows/steps/panel/query_options/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def time_shift_textfield(self):
def hide_time_info_toggle(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[@class="gf-form-inline align-items-center" and .//text()="Hide time info"]//label[@aria-label="Toggle switch"]')
f'//*[contains(@class,"InlineFieldRow") and .//text()="Hide time info"]//label[@aria-label="Toggle switch"]')

@property
def relative_time_info(self):
Expand Down
28 changes: 19 additions & 9 deletions tests/testflows/steps/panel/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def get_query_inspector_url_text(self):
with By("getting url from query inspector"):
return locators.query_inspector_url.text

@TestStep(When)
def click_query_inspector_close_button(self):
"""Click query inspector close button."""

locators.query_inspector_close_button.click()

@TestStep(Then)
def check_query_inspector_request(self, url_parts):
Expand All @@ -285,10 +290,15 @@ def check_query_inspector_request(self, url_parts):
with delay():
click_inspect_query_refresh_button()

with By("checking url contains necessary parts"):
for url_part in url_parts:
with By(f"checking url contains {url_part}"):
assert url_part in get_query_inspector_url_text(), error()
try:
with By("checking url contains necessary parts"):
for url_part in url_parts:
with By(f"checking url contains {url_part}"):
assert url_part in get_query_inspector_url_text(), error()
finally:
with Finally("I close query inspector window"):
with By("clicking query inspector close button"):
click_query_inspector_close_button()


@TestStep(When)
Expand Down Expand Up @@ -407,9 +417,9 @@ def click_apply_button(self):

@TestStep(When)
def click_discard_button(self):
"""Click apply button for panel."""
"""Click discard button for panel."""

locators.discard_button.click()
locators.discard_button(grafana_version=self.context.grafana_version).click()


@TestStep(When)
Expand Down Expand Up @@ -501,14 +511,14 @@ def get_value_from_table(self, time):
def click_save_button(self):
"""Click save button."""

locators.save_button.click()
locators.save_button(grafana_version=self.context.grafana_version).click()


@TestStep(When)
def click_save_confirmation_button(self):
"""Click save confirmation button."""

locators.save_confirmations_button.click()
locators.save_confirmations_button(grafana_version=self.context.grafana_version).click()


@TestStep(When)
Expand All @@ -519,5 +529,5 @@ def save_dashboard(self):
click_save_button()

with And("clicking save confirmation button"):
with delay():
with delay(before=0.5):
click_save_confirmation_button()
5 changes: 3 additions & 2 deletions tests/testflows/steps/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_local_chrome_driver(self, browser, local_webdriver_path, common_optio
chrome_options.add_argument("--no-sandbox")
if is_headless:
chrome_options.add_argument("--headless")
chrome_options.add_argument("window-size=1560,1160")
chrome_options.add_argument("window-size=2000,1200")
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--v=1')

Expand All @@ -89,12 +89,13 @@ def create_remote_chrome_driver(self, browser, hub_url, common_options, timeout,
"credentials_enable_service": False,
"profile.password_manager_enabled": False,
}
remote_chrome_options.add_argument("--disable-notifications")
remote_chrome_options.add_experimental_option("prefs", remote_chrome_prefs)
remote_chrome_options.set_capability("browserName", browser)
remote_chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
remote_chrome_options.add_experimental_option("useAutomationExtension", False)
remote_chrome_options.set_capability("se:recordVideo", "true")
remote_chrome_options.set_capability("se:screenResolution", "1920x1080")
remote_chrome_options.set_capability("se:screenResolution", "2000x1200")

start_time = time.time()

Expand Down
Loading
Loading