Skip to content

Commit

Permalink
merge 1.20.29rc3 to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
98llm committed Dec 30, 2024
1 parent a60a213 commit 03ba3b3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tir/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=''):
"""
Expand Down
52 changes: 41 additions & 11 deletions tir/technologies/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tir/technologies/core/base_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions tir/technologies/core/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"

}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": "Пользователь",
Expand Down Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions tir/technologies/poui_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
38 changes: 32 additions & 6 deletions tir/technologies/webapp_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)}"
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 03ba3b3

Please sign in to comment.