diff --git a/automon/integrations/seleniumWrapper/browser.py b/automon/integrations/seleniumWrapper/browser.py index d883878a..38290b9a 100644 --- a/automon/integrations/seleniumWrapper/browser.py +++ b/automon/integrations/seleniumWrapper/browser.py @@ -40,6 +40,7 @@ def __init__(self, config: SeleniumConfig = None): self.autosaved = None self.logs = {} + self.cache = {} def __repr__(self): try: @@ -524,6 +525,7 @@ def find_anything( case_sensitive: bool = False, exact_match: bool = False, return_first: bool = False, + caching: bool = True, **kwargs) -> list: """fuzzy search through everything @@ -553,7 +555,21 @@ def find_anything( MATCHED = [] for by_ in by_types: - elements = self.find_elements(value=value, by=by_, **kwargs) + # try caching the elements + if caching: + if by_ not in self.cache.keys(): + self.cache[by_] = {} + self.cache[by_][value] = self.find_elements(value=value, by=by_, **kwargs) + + elif value not in self.cache[by_].keys(): + self.cache[by_][value] = self.find_elements(value=value, by=by_, **kwargs) + + else: + self.cache[by_] = {} + self.cache[by_][value] = self.find_elements(value=value, by=by_, **kwargs) + + elements = self.cache[value] + for element in elements: dirs = dir(element) dir_meta = [] @@ -922,7 +938,7 @@ def wait_for_anything( logger.debug( f'wait_for_anything :: ' - f'timeout {timeout_elapsed}/{timeout} :: ' + f'timeout {timeout_elapsed}/{timeout} sec :: ' f'{self.current_url=} :: ' f'{value=} :: ' f'{by=}' @@ -947,7 +963,6 @@ def wait_for_anything( logger.error(f'wait_for_anything :: failed :: {error=} :: {match=} :: {value=} :: {by=}') timeout_elapsed = round(abs(timeout_start - time.time()), 1) - logger.debug(f'wait_for_anything :: {timeout_elapsed} seconds elapsed') raise ElementNotFoundException(f'wait_for_anything :: failed :: {match=} :: {value=} :: {by=}') @@ -966,7 +981,12 @@ def wait_for_element( while timeout_elapsed < timeout: logger.debug( - f'wait_for_element :: {f"{timeout_elapsed}/{timeout}"} :: {by=} :: {self.current_url} :: {value=}') + f'wait_for_element :: ' + f'timeout {timeout_elapsed}/{timeout} sec :: ' + f'{by=} :: ' + f'{self.current_url} :: ' + f'{value=}' + ) try: find = self.find_element( @@ -983,7 +1003,6 @@ def wait_for_element( logger.error(f'wait_for_element :: failed :: {error=} :: {value=} :: {by=}') timeout_elapsed = round(abs(timeout_start - time.time()), 1) - logger.debug(f'wait_for_element :: {timeout_elapsed} seconds elapsed') raise ElementNotFoundException(f'wait_for_element :: failed :: {value=} :: {by=}') @@ -1002,7 +1021,12 @@ def wait_for_elements( while timeout_elapsed < timeout: logger.debug( - f'wait_for_element :: {f"{timeout_elapsed}/{timeout}"} :: {by=} :: {self.current_url} :: {value=}') + f'wait_for_element :: ' + f'timeout {timeout_elapsed}/{timeout} sec :: ' + f'{by=} :: ' + f'{self.current_url} :: ' + f'{value=}' + ) try: find = self.find_elements( @@ -1019,7 +1043,6 @@ def wait_for_elements( logger.error(f'wait_for_elements :: failed :: {error=} :: {value=} :: {by=}') timeout_elapsed = round(abs(timeout_start - time.time()), 1) - logger.debug(f'wait_for_elements :: {timeout_elapsed} seconds elapsed') raise ElementNotFoundException(f'wait_for_elements :: failed :: {value=} :: {by=}')