Skip to content

Commit

Permalink
Merge pull request #9704 from DanielOsypenko/runbooks-clear-searchfie…
Browse files Browse the repository at this point in the history
…ld-upd

update the search cleanup with gradual text removal
  • Loading branch information
petr-balogh authored Apr 24, 2024
2 parents 520831e + 5ff874d commit c504521
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
29 changes: 29 additions & 0 deletions ocs_ci/ocs/ui/base_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
"""
Expand Down
22 changes: 1 addition & 21 deletions ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ocs_ci/ocs/ui/page_objects/searchbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
20 changes: 11 additions & 9 deletions tests/functional/ui/test_alert_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c504521

Please sign in to comment.