From 03ba3b33c778d7ef292e7264c4118f9d70207b0a Mon Sep 17 00:00:00 2001 From: 98llm Date: Mon, 30 Dec 2024 15:49:47 -0300 Subject: [PATCH] merge 1.20.29rc3 to 2.0 --- tir/main.py | 2 +- tir/technologies/core/base.py | 52 ++++++++++++++++++++------ tir/technologies/core/base_database.py | 2 +- tir/technologies/core/language.py | 15 ++++++-- tir/technologies/poui_internal.py | 4 +- tir/technologies/webapp_internal.py | 38 ++++++++++++++++--- 6 files changed, 88 insertions(+), 25 deletions(-) diff --git a/tir/main.py b/tir/main.py index ca5053109..834ba9bdf 100644 --- a/tir/main.py +++ b/tir/main.py @@ -1161,7 +1161,7 @@ def ProgramScreen(self, initial_program=""): >>> # Calling the method: >>> self.oHelper.ProgramScreen("SIGAADV") """ - self.__webapp.program_screen(initial_program, coverage=self.coverage) + self.__webapp.program_screen(initial_program) def OpenCSV(self, csv_file='', delimiter=';', column=None, header=None, filter_column=None, filter_value=''): """ diff --git a/tir/technologies/core/base.py b/tir/technologies/core/base.py index 1d1729a62..88eae4c82 100644 --- a/tir/technologies/core/base.py +++ b/tir/technologies/core/base.py @@ -547,18 +547,36 @@ def switch_to_iframe(self): if not self.config.poui: iframes = None - iframe_displayed = None + filtered_iframe = None endtime = time.time() + self.config.time_out while time.time() < endtime and not iframes: iframes = self.driver.find_elements(By.CSS_SELECTOR, '[class*="twebview"], [class*="dict-twebengine"]') if iframes: - iframe_displayed = next(iter(list(filter(lambda x: x.is_displayed(), iframes))), None) + filtered_iframe = self.filter_active_iframe(iframes) else: self.driver.switch_to.default_content() - if iframe_displayed: - self.driver.switch_to.frame(self.find_shadow_element('iframe', iframe_displayed)[0]) if self.webapp_shadowroot() else self.driver.switch_to.frame(iframe_displayed) + if filtered_iframe: + self.driver.switch_to.frame(self.find_shadow_element('iframe', filtered_iframe)[0]) if self.webapp_shadowroot() else self.driver.switch_to.frame(filtered_iframe) + + + def filter_active_iframe(self, iframes): + ''' + + :param iframes: + :type List + :return: + ''' + iframes_displayed = [] + + iframes_displayed = list(filter(lambda x: x.is_displayed(), iframes)) + iframes_filtred_zindex = list(filter(lambda x: x.get_attribute('style').split("z-index:")[1].split(";")[0].strip(), iframes_displayed)) + if iframes_displayed and len(iframes_filtred_zindex) == len(iframes_displayed): + return max(iframes_filtred_zindex, key=lambda x: int(x.get_attribute('style').split("z-index:")[1].split(";")[0].strip())) + if not iframes_displayed: + return None + def get_element_text(self, element): """ @@ -757,7 +775,7 @@ def scroll_into_view(self, element): except Exception as e: logger().debug(f"********Warining scroll_to_element exception: {str(e)}*********") pass - + def search_zindex(self,element): """ [Internal] @@ -874,7 +892,7 @@ def return_selected_combo_value(self, element): else: return '' - def send_keys(self, element, arg): + def send_keys(self, element, arg, send_type=1): """ [Internal] @@ -884,7 +902,8 @@ def send_keys(self, element, arg): :type element: Selenium object :param arg: Text or Keys to be sent to the element :type arg: str or selenium.webdriver.common.keys - + :param send_type: Send Keys type can be do it Selenium or ActionChains + :type send_type: Int Usage: >>> #Defining the element: @@ -895,10 +914,21 @@ def send_keys(self, element, arg): >>> self.send_keys(element(), Keys.ENTER) """ try: - if arg.isprintable(): - element.clear() - element.send_keys(Keys.CONTROL, 'a') - element.send_keys(arg) + if send_type == 1: + if arg.isprintable(): + element.clear() + element.send_keys(Keys.CONTROL, 'a') + element.send_keys(arg) + elif send_type == 2: + actions = ActionChains(self.driver) + actions.move_to_element(element) + actions.click() + if arg.isprintable(): + actions.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).send_keys(Keys.DELETE) + actions.send_keys(Keys.HOME) + actions.send_keys(arg) + actions.perform() + except Exception: actions = ActionChains(self.driver) actions.move_to_element(element) diff --git a/tir/technologies/core/base_database.py b/tir/technologies/core/base_database.py index 48a378ffd..4ae41fbfc 100644 --- a/tir/technologies/core/base_database.py +++ b/tir/technologies/core/base_database.py @@ -61,7 +61,7 @@ def disconnect_database(self, connection): logger().info('DataBase connection stopped') else: logger().info('DataBase connection already stopped') - + def query_execute(self, query, database_driver, dbq_oracle_server, database_server, database_port, database_name, database_user, database_password): """ Return a dictionary if the query statement is a SELECT otherwise print a number of row diff --git a/tir/technologies/core/language.py b/tir/technologies/core/language.py index 48a485ee9..16c82d587 100644 --- a/tir/technologies/core/language.py +++ b/tir/technologies/core/language.py @@ -87,6 +87,7 @@ def __init__(self, language="pt-BR"): self.success = languagepack["Success"] self.procedure_install = languagepack["Procedure Install"] self.procedure_uninstall = languagepack["Procedure Uninstall"] + self.schedule_menu = languagepack["Schedule Menu"] self.messages = Messages(languagepack) @@ -182,7 +183,8 @@ def get_language_pack(self, language): "Code": "Code", "Success": "Success", "Procedure Install": "Install selected processes", - "Procedure Uninstall": "Remove selected processes" + "Procedure Uninstall": "Remove selected processes", + "Schedule Menu": "Settings > Schedule > Schedule" } @@ -276,7 +278,9 @@ def get_language_pack(self, language): "Code": "Código", "Success": "Sucessos", "Procedure Install": "Instalar processos selecionados", - "Procedure Uninstall": "Remover processos selecionados" + "Procedure Uninstall": "Remover processos selecionados", + "Schedule Menu": "Ambiente > Schedule > Schedule" + } spanish = { "User": "Usuário", @@ -368,7 +372,9 @@ def get_language_pack(self, language): "Code": "Código", "Success": "Sucessos", "Procedure Install": "Instalar processos selecionados", - "Procedure Uninstall": "Remover processos selecionados" + "Procedure Uninstall": "Remover processos selecionados", + "Schedule Menu": "Entorno > Schedule > Schedule" + } russian = { "User": "Пользователь", @@ -462,7 +468,8 @@ def get_language_pack(self, language): "Code": "Код", "Success": "успех", "Procedure Install": "Установить выбранные процессы", - "Procedure Uninstall": "Удалить выбранные процессы" + "Procedure Uninstall": "Удалить выбранные процессы", + "Schedule Menu": "Settings > Schedule > Schedule" } if language.lower() == "en-us": diff --git a/tir/technologies/poui_internal.py b/tir/technologies/poui_internal.py index 3da696c36..ff7f74eda 100644 --- a/tir/technologies/poui_internal.py +++ b/tir/technologies/poui_internal.py @@ -294,7 +294,7 @@ def user_screen(self, admin_user = False): password_value = self.get_web_value(password()) endtime = time.time() + self.config.time_out try_counter = 0 - while (time.time() < endtime and not password_value and self.config.password != ''): + while (time.time() < endtime and not password_value.strip() and self.config.password != ''): if try_counter == 0: password = lambda: self.soup_to_selenium(password_element) @@ -310,7 +310,7 @@ def user_screen(self, admin_user = False): password_value = self.get_web_value(password()) try_counter += 1 if(try_counter < 1) else -1 - if not password_value and self.config.password != '': + if not password_value.strip() and self.config.password != '': self.restart_counter += 1 message = "Couldn't fill User input element." self.log_error(message) diff --git a/tir/technologies/webapp_internal.py b/tir/technologies/webapp_internal.py index b97595249..9c6d56296 100644 --- a/tir/technologies/webapp_internal.py +++ b/tir/technologies/webapp_internal.py @@ -241,7 +241,10 @@ def Setup(self, initial_program, date='', group='99', branch='01', module='', sa logger().info(f"***System Info*** in Setup():") system_info() - self.config.poui_login = ConfigLoader(self.config_path).poui_login + if 'POUILogin' in self.config.json_data and self.config.json_data['POUILogin'] == True: + self.config.poui_login = True + else: + self.config.poui_login = False try: self.service_process_bat_file() @@ -861,7 +864,12 @@ def filling_date(self, shadow_root=None, container=None): ActionChains(self.driver).key_down(Keys.CONTROL).send_keys(Keys.HOME).key_up(Keys.CONTROL).perform() ActionChains(self.driver).key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys( Keys.END).key_up(Keys.CONTROL).key_up(Keys.SHIFT).perform() - self.send_keys(date(), self.config.date) + + if self.config.browser.lower() == "chrome": + self.send_keys(date(), self.config.date, send_type=2) + else: + self.send_keys(date(), self.config.date) + base_date_value = self.merge_date_mask(self.config.date, self.get_web_value(date())) if self.config.poui_login: ActionChains(self.driver).send_keys(Keys.TAB * 2).perform() @@ -2884,7 +2892,6 @@ def input_value(self, field, value, ignore_case=True, name_attr=False, position= if not check_value: return - self.wait_blocker() if self.check_combobox(element): current_value = current_value[0:len(str(value))] @@ -7654,6 +7661,7 @@ def get_selected_row(self, rows): return next(iter(list(filter(lambda x: "selected-row" == self.soup_to_selenium(x).get_attribute('class'), rows))), None) return next(reversed(rows), None) + def SetFilePath(self, value, button = ""): """ Fills the path screen with the desired path @@ -8176,7 +8184,12 @@ def AddParameter(self, parameter, branch, portuguese_value, english_value="", sp """ logger().info(f"AddParameter: {parameter}") - twebview = True if ConfigLoader(self.config_path).poui_login else False + + if 'POUILogin' in self.config.json_data and self.config.json_data['POUILogin'] == True: + twebview = True + else: + twebview = False + endtime = time.time() + self.config.time_out halftime = ((endtime - time.time()) / 2) @@ -8258,7 +8271,12 @@ def parameter_url(self, restore_backup=False): >>> self.parameter_url(restore_backup=False) """ try_counter = False - twebview = True if ConfigLoader(self.config_path).poui_login else False + + if 'POUILogin' in self.config.json_data and self.config.json_data['POUILogin'] == True: + twebview = True + else: + twebview = False + endtime = time.time() + self.config.time_out halftime = ((endtime - time.time()) / 2) function_to_call = "u_SetParam" if restore_backup is False else "u_RestorePar" @@ -9461,7 +9479,10 @@ def TearDown(self): logger().exception(str(e)) webdriver_exception = e - self.config.poui_login = ConfigLoader(self.config_path).poui_login + if 'POUILogin' in self.config.json_data and self.config.json_data['POUILogin'] == True: + self.config.poui_login = True + else: + self.config.poui_login = False if webdriver_exception: message = f"Wasn't possible execute self.driver.refresh() Exception: {next(iter(webdriver_exception.msg.split(':')), None)}" @@ -10736,6 +10757,11 @@ def find_shadow_element(self, term, objects, get_all=True): elements = self.driver.execute_script(script, objects) except: pass + + if not elements: + script = f"return arguments[0].querySelectorAll('{term}')" + elements = self.driver.execute_script(script, objects) + return elements if elements else None def return_soup_by_selenium(self, elements, term, selectors):