diff --git a/tir/main.py b/tir/main.py index 32defc58..d949b4af 100644 --- a/tir/main.py +++ b/tir/main.py @@ -30,6 +30,19 @@ def __init__(self, config_path="", autostart=True): self.coverage = self.config.coverage self._subscribe_routes() + def __getattribute__(self, name): + attr = object.__getattribute__(self, name) + + if callable(attr) and not name.startswith('_'): + preserve_methods = {'SearchBrowse', 'SetButton'} + if name not in preserve_methods: + try: + object.__getattribute__(self, 'config')._flag_is_new_browse = None + except AttributeError: + pass + + return attr + def _subscribe_routes(self): """Registra handlers do Router no event bus para roteamento. @@ -641,7 +654,7 @@ def SetBranch(self, branch): """ self.__webapp.SetBranch(branch) - def SetButton(self, button, sub_item="", position=1, check_error=True): + def SetButton(self, button, sub_item="", position=1, check_error=True, is_browse=False): """ Method that clicks on a button on the screen. @@ -674,7 +687,7 @@ def SetButton(self, button, sub_item="", position=1, check_error=True): >>> # Calling the method to click on a sub item in a sub item that is inside a button. >>> oHelper.SetButton("Other Actions", "Delete, Delete") """ - self.__router.SetButton(button, sub_item, position, check_error=check_error) + self.__router.SetButton(button, sub_item, position, check_error=check_error, is_browse=is_browse) def SetFilePath(self, value, button = ""): """ @@ -1703,6 +1716,19 @@ def __init__(self, config_path="", autostart=True): self.config = ConfigLoader() self.coverage = self.config.coverage + def __getattribute__(self, name): + attr = object.__getattribute__(self, name) + + if callable(attr) and not name.startswith('_'): + preserve_methods = {'SearchBrowse', 'SetButton'} + if name not in preserve_methods: + try: + object.__getattribute__(self, 'config')._flag_is_new_browse = None + except AttributeError: + pass + + return attr + def ClickMenu(self, menu_item): """ Clicks on the menu-item of the POUI component. diff --git a/tir/technologies/core/config.py b/tir/technologies/core/config.py index b1512393..75e7a764 100644 --- a/tir/technologies/core/config.py +++ b/tir/technologies/core/config.py @@ -130,6 +130,7 @@ def _initialize(self, path="config.json"): self.server_mock = str(data["ServerMock"]) if "ServerMock" in data else "" self.sso_login = ("SSOLogin" in data and bool(data["SSOLogin"])) self.new_home = ("NewHome" in data and bool(data["NewHome"])) + self._flag_is_new_browse = None def check_keys(self, json_data): diff --git a/tir/technologies/core/router.py b/tir/technologies/core/router.py index dda93a9c..658c75ad 100644 --- a/tir/technologies/core/router.py +++ b/tir/technologies/core/router.py @@ -133,26 +133,25 @@ def set_log_info(self) -> None: drv = self._get_driver_instance(lambda: self.config.new_home) drv.set_log_info() - def SetButton(self, button, sub_item="", position=1, check_error=True) -> None: + def SetButton(self, button, sub_item="", position=1, check_error=True, is_browse=False) -> None: """Click on button using appropriate driver (POUI or WebApp).""" - view = self.language.view - change = self.language.old_browse_edit - other_actions = self.language.other_actions - delete = self.language.old_browse_delete - add = self.language.old_browse_insert + if is_browse: + use_poui = self._ensure_webapp()._is_new_browse(throw_error=False, timeout=self.config.time_out) + else: + use_poui = self.config._flag_is_new_browse if self.config._flag_is_new_browse is not None else False - new_browse_buttons = {view, change, other_actions, delete, add} + # Consume flag: only first SetButton after SearchBrowse uses it. + self.config._flag_is_new_browse = None - drv = self._get_driver_instance( - lambda: button in new_browse_buttons and self._ensure_webapp()._is_new_browse(throw_error=False) - ) + drv = self._get_driver_instance(lambda: use_poui) drv.SetButton(button, sub_item, position, check_error=check_error) def SearchBrowse(self, term=None, key=None, identifier=None, index=False, column=None, filters=[]) -> None: - drv = self._get_driver_instance( - lambda: filters and self._ensure_webapp()._is_new_browse(throw_error=False) - ) + use_poui = self._ensure_webapp()._is_new_browse(throw_error=False, timeout=self.config.time_out) + self.config._flag_is_new_browse = use_poui + + drv = self._get_driver_instance(lambda: use_poui) drv.SearchBrowse(term=term, key=key, identifier=identifier, index=index, column=column, filters=filters) diff --git a/tir/technologies/webapp_internal.py b/tir/technologies/webapp_internal.py index d638e111..795b1c87 100644 --- a/tir/technologies/webapp_internal.py +++ b/tir/technologies/webapp_internal.py @@ -2055,8 +2055,8 @@ def _simple_search_thf_browse(self, search_text, browse_div): return - def _is_new_browse(self, throw_error=True): - browse_div = self._find_search_browse(throw_error=throw_error, timeout=5) + def _is_new_browse(self, throw_error=True, timeout=None): + browse_div = self._find_search_browse(throw_error=throw_error, timeout=timeout) return browse_div.name == 'thf-grid' if browse_div else False @@ -2129,7 +2129,7 @@ def _find_search_browse(self, panel_name=None, throw_error=True, timeout=None): container_term = 'wa-tab-page > wa-dialog' container = None - elements_soup = None + elements_soup = [] browse_div = [] endtime = time.time() + (timeout if timeout is not None else self.config.time_out) @@ -2138,11 +2138,11 @@ def _find_search_browse(self, panel_name=None, throw_error=True, timeout=None): soup = self.get_current_DOM() containers = self.zindex_sort(soup.select(container_term), reverse=True) container = next(iter(containers), None) + elements_soup = [] if container: elements_soup = container.select("[style*='fwskin_seekbar_ico']") - - elements_soup = list(filter(lambda x: self.element_is_displayed(x), elements_soup)) + elements_soup = list(filter(lambda x: self.element_is_displayed(x), elements_soup)) if elements_soup else [] if elements_soup: if elements_soup and len(elements_soup) - 1 >= search_index: