From 5ff874dc6e848b779bc4f0aa9198cef2e283aa91 Mon Sep 17 00:00:00 2001 From: Daniel Osypenko Date: Sun, 21 Apr 2024 18:40:01 +0300 Subject: [PATCH] update search cleanup with gradual text removal Signed-off-by: Daniel Osypenko --- ocs_ci/ocs/ui/base_ui.py | 29 +++++++++++++++++++ .../data_foundation_tabs_common.py | 22 +------------- ocs_ci/ocs/ui/page_objects/searchbar.py | 2 +- tests/functional/ui/test_alert_text.py | 20 +++++++------ 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/ocs_ci/ocs/ui/base_ui.py b/ocs_ci/ocs/ui/base_ui.py index 2e4b9ea6875..1c6dd2146d8 100644 --- a/ocs_ci/ocs/ui/base_ui.py +++ b/ocs_ci/ocs/ui/base_ui.py @@ -667,6 +667,35 @@ def wait_for_endswith_url(self, endswith, timeout=60): wait = WebDriverWait(self.driver, timeout=timeout) wait.until(ec.url_matches(endswith)) + def clear_input_gradually(self, locator): + """ + Clean input field by gradually deleting characters one by one. + This way we avoid common automation issue when input field is not cleared. + + Returns: + bool: True if the input element is successfully cleared, False otherwise. + """ + wait_for_element_to_be_visible(locator, 30) + elements = self.get_elements(locator) + input_el = elements[0] + input_len = len(str(input_el.get_attribute("value"))) + + # timeout in seconds will be equal to a number of symbols to be removed, but not less than 30s + timeout = input_len if input_len > 30 else 30 + timeout = time.time() + timeout + if len(elements): + while len(str(input_el.get_attribute("value"))) != 0: + if time.time() < timeout: + # to remove text from the input independently where the caret is use both delete and backspace + input_el.send_keys(Keys.BACKSPACE, Keys.DELETE) + time.sleep(0.05) + else: + raise TimeoutException("time to clear input os out") + else: + logger.error("test input locator not found") + return False + return True + def screenshot_dom_location(type_loc="screenshot"): """ diff --git a/ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py b/ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py index 5fa381d9832..656b343a137 100644 --- a/ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py +++ b/ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py @@ -7,7 +7,6 @@ import pandas as pd from selenium.common.exceptions import TimeoutException, NoSuchElementException -from selenium.webdriver.common.keys import Keys from ocs_ci.ocs.ui.helpers_ui import format_locator from ocs_ci.ocs.ui.page_objects.resource_page import ResourcePage from ocs_ci.utility.retry import retry @@ -160,26 +159,7 @@ def _remove_text_from_input(self) -> bool: Returns: bool: True if the input element is successfully cleared, False otherwise. """ - wait_for_element_to_be_visible(self.name_input_loc, 30) - elements = self.get_elements(self.name_input_loc) - input_el = elements[0] - input_len = len(str(input_el.get_attribute("value"))) - - # timeout in seconds will be equal to a number of symbols to be removed, but not less than 30s - timeout = input_len if input_len > 30 else 30 - timeout = time.time() + timeout - if len(elements): - while len(str(input_el.get_attribute("value"))) != 0: - if time.time() < timeout: - # to remove text from the input independently where the caret is use both delete and backspace - input_el.send_keys(Keys.BACKSPACE, Keys.DELETE) - time.sleep(0.05) - else: - raise TimeoutException("time to clear input os out") - else: - logger.error("test input locator not found") - return False - return True + return self.clear_input_gradually(self.name_input_loc) def _check_input_text_length( self, rule_exp: str, text_length: int, status_expected: str diff --git a/ocs_ci/ocs/ui/page_objects/searchbar.py b/ocs_ci/ocs/ui/page_objects/searchbar.py index a09206c61ed..cc3376ce407 100644 --- a/ocs_ci/ocs/ui/page_objects/searchbar.py +++ b/ocs_ci/ocs/ui/page_objects/searchbar.py @@ -42,4 +42,4 @@ def clear_search(self): """ logger.info("Clear search input") - self.do_clear(self.generic_locators["searchbar_input"]) + self.clear_input_gradually(self.generic_locators["searchbar_input"]) diff --git a/tests/functional/ui/test_alert_text.py b/tests/functional/ui/test_alert_text.py index ac68664af82..3f137321f90 100644 --- a/tests/functional/ui/test_alert_text.py +++ b/tests/functional/ui/test_alert_text.py @@ -117,12 +117,14 @@ def test_runbooks(setup_ui, alerts_expected): test_res[alert_name] = text_as_expected and text_valid - test_res_df = pd.DataFrame.from_dict( - test_res, orient="index", columns=["Runbook Hash Match"] - ) - alerts_failed_check = test_res_df[ - not test_res_df["Runbook Hash Match"] - ].to_markdown(headers="keys", index=True, tablefmt="grid") - assert all( - test_res.values() - ), f"Failed to match runbook hash for alerts: \n{alerts_failed_check}" + assert_msg = "Failed to match runbook hash for alerts: \n" + if test_res: + test_res_df = pd.DataFrame.from_dict( + test_res, orient="index", columns=["Runbook Hash Match"] + ) + alerts_failed_check = test_res_df[ + ~test_res_df["Runbook Hash Match"] + ].to_markdown(headers="keys", index=True, tablefmt="grid") + assert_msg = f"{assert_msg}{alerts_failed_check}" + + assert all(test_res.values()), assert_msg