Skip to content

Commit

Permalink
Merge pull request #1388 from totvs/release/v1.20.17
Browse files Browse the repository at this point in the history
Release/v1.20.17
  • Loading branch information
98llm authored Jan 24, 2024
2 parents 055be16 + 1d727fc commit a4e9a45
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/install_package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ taskkill /f /im chromedriver.exe
echo -------------------------
echo Installing project...
echo -------------------------
pip install -U dist/tir_framework-1.20.16.tar.gz
pip install -U dist/tir_framework-1.20.17.tar.gz
pause >nul | set/p = Press any key to exit ...
17 changes: 17 additions & 0 deletions tir/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,23 @@ def GetLineNumber(self, values, columns=[], grid_number=0):
return self.__webapp.GetLineNumber(values,columns, grid_number)


def SetCalendar(self, day='', month='', year=''):
"""
Set date on Calendar without input field
:param day: day disered
:type day: str
:param month: month disered
:type month: str
:param year: year disered
:type year: str
"""
return self.__webapp.SetCalendar(day, month, year)


class Apw():

def __init__(self, config_path=""):
Expand Down
37 changes: 35 additions & 2 deletions tir/technologies/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ def web_scrap(self, term, scrap_type=enum.ScrapType.TEXT, optional_term=None, la
except Exception as e:
self.log_error(str(e))

def zindex_sort (self, elements, reverse=False):
def zindex_sort (self, elements, reverse=False, active_tab=True):
"""
[Internal]
Expand All @@ -1018,7 +1018,10 @@ def zindex_sort (self, elements, reverse=False):
>>> #Calling the method
>>> self.zindex_sort(elements, True)
"""
if isinstance(elements, list):
if active_tab:
elements = self.return_active_element(elements, reverse)
else:
isinstance(elements, list)
elements.sort(key=lambda x: self.search_zindex(x), reverse=reverse)

return elements
Expand Down Expand Up @@ -1387,3 +1390,33 @@ def find_by_locator(self, locator, selector, shadow_root):
self.log_error(f"Element {element} doesn't found")

return element

def return_active_element(self, elements, reverse):

if isinstance(elements, list):
filtered_element = list(
filter(lambda x: hasattr(x.find_parent('wa-tab-page'), 'attrs') if x else None, elements))

if filtered_element:
non_blocked_element = self.return_non_blocked_elements(filtered_element, reverse)
active_element = list(filter(lambda x: 'active' in x.find_parent('wa-tab-page').attrs, non_blocked_element))
if active_element:
return active_element
else:
return self.return_non_blocked_elements(elements, reverse)
else:
return self.return_non_blocked_elements(elements, reverse)
else:
return elements

def return_non_blocked_elements(self, elements, reverse):

non_blocked_elements = list(filter(lambda x: hasattr(x, 'attr') and 'blocked' not in x.attrs, elements))

if isinstance(non_blocked_elements, list):
if len(non_blocked_elements) > 1:
if reverse:
return non_blocked_elements[::-1]
return non_blocked_elements
else:
return non_blocked_elements
119 changes: 112 additions & 7 deletions tir/technologies/webapp_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ def filling_date(self, shadow_root=None, container=None):

click_type = 1
base_date_value = ''
base_dates = None
endtime = time.time() + self.config.time_out / 5
while (time.time() < endtime and (base_date_value.strip() != self.config.date.strip())):

Expand Down Expand Up @@ -863,6 +864,7 @@ def filling_group(self, shadow_root=None, container=None):

click_type = 1
group_value = ''
group_element = None
endtime = time.time() + self.config.time_out / 5
while (time.time() < endtime and (group_value.strip() != self.config.group.strip())):

Expand Down Expand Up @@ -920,6 +922,7 @@ def filling_branch(self, shadow_root=None, container=None):

click_type = 1
branch_value = ''
branch_element = None
endtime = time.time() + self.config.time_out / 5
while (time.time() < endtime and (branch_value.strip() != self.config.branch.strip())):

Expand Down Expand Up @@ -977,6 +980,7 @@ def filling_environment(self, shadow_root=None, container=None):

click_type = 1
env_value = ''
environment_element = None
enable = True
endtime = time.time() + self.config.time_out / 5
while (time.time() < endtime and env_value.strip() != self.config.module.strip() and enable):
Expand Down Expand Up @@ -3460,6 +3464,9 @@ def web_scrap(self, term, scrap_type=enum.ScrapType.TEXT, optional_term=None, la

containers = self.zindex_sort(soup.select(container_selector), reverse=True)

if container_selector == 'wa-text-view':
return self.filter_label_element(term, container=soup, position=position, twebview=twebview) if self.filter_label_element(term, container=soup, position=position, twebview=twebview) else []

if self.base_container in container_selector:
container = self.containers_filter(containers)

Expand Down Expand Up @@ -6228,6 +6235,10 @@ def fill_grid(self, field, x3_dictionaries, initial_layer, duplicate_fields=[]):
self.set_element_focus(selenium_input())
self.click(selenium_input())

endtime_container = time.time() + self.config.time_out
while time.time() < endtime_container and 'class' not in self.get_current_container().next.attrs:
logger().info('Waiting container attributes')

if 'tget' in self.get_current_container().next.attrs['class'] or 'tmultiget' in \
self.get_current_container().next.attrs['class'] \
or 'dict-tget' in self.get_current_container().next.attrs['class']:
Expand All @@ -6249,6 +6260,10 @@ def fill_grid(self, field, x3_dictionaries, initial_layer, duplicate_fields=[]):

modal_open = self.wait_element_timeout(term='wa-dialog', scrap_type=enum.ScrapType.CSS_SELECTOR, position= tmodal_layer + 1, timeout=10, presence=True, main_container='body', check_error=False)

endtime_container = time.time() + self.config.time_out
while time.time() < endtime_container and 'id' not in self.get_current_container().attrs:
logger().info('Waiting container attributes')

if (("_" in field[0] and field_to_len != {} and int(field_to_len[field[0]]) > len(
field[1])) or lenfield > len(field[1])) and modal_open:
if (("_" in field[0] and field_to_valtype != {} and field_to_valtype[
Expand Down Expand Up @@ -7469,7 +7484,7 @@ def SetFilePath(self, value, button = ""):
if element:
self.driver.execute_script("document.querySelector('wa-file-picker').shadowRoot.querySelector('#{}').value='';".format(element.get_attribute("id")))

self.send_keys(element, value)
self.send_keys(element, self.replace_slash(value))
elements = self.driver.execute_script(f"return arguments[0].shadowRoot.querySelectorAll('button')", self.soup_to_selenium(containers_soup))
possible_buttons = button.upper() + '_' + self.language.open.upper() + '_' + self.language.save.upper()
elements = list(filter(lambda x: x.text.strip().upper() in possible_buttons, elements ))
Expand All @@ -7479,7 +7494,7 @@ def SetFilePath(self, value, button = ""):

if element:
self.driver.execute_script("document.querySelector('#{}').value='';".format(element.get_attribute("id")))
self.send_keys(element, value)
self.send_keys(element, self.replace_slash(value))
elements = self.driver.find_elements(By.CSS_SELECTOR, ".tremoteopensave button")

if elements:
Expand All @@ -7497,6 +7512,14 @@ def SetFilePath(self, value, button = ""):

self.log_error(f"Button: {button} not found")

def replace_slash(self, path):

slash = r"/" if (sys.platform.lower() == "linux") else r"\\"

pattern = re.compile(r'[\/\\]')

if pattern.findall(path):
return pattern.sub(slash, path)

def MessageBoxClick(self, button_text):
"""
Expand Down Expand Up @@ -8479,7 +8502,7 @@ def ClickCheckBox(self, label_box_name, position=1, double_click=False):
if not success:
self.log_error("Checkbox index is invalid.")

def ClickLabel(self, label_name):
def ClickLabel(self, label_name, position=0):
"""
Clicks on a Label on the screen.
Expand All @@ -8493,6 +8516,8 @@ def ClickLabel(self, label_name):
"""
bs_label = ''
label = ''
filtered_labels = []
self.wait_blocker()
self.wait_element(label_name)
logger().info(f"Clicking on {label_name}")
endtime = time.time() + self.config.time_out
Expand All @@ -8502,21 +8527,41 @@ def ClickLabel(self, label_name):
self.log_error("Couldn't locate container.")

if self.webapp_shadowroot():
labels = container.select("wa-text-view, wa-checkbox")
filtered_labels = next(iter(list(filter(lambda x: x.get('caption') and label_name.lower() == x.get('caption').lower(), labels))),None)

labels = container.select("wa-text-view, wa-checkbox, .dict-tradmenu")
for element in labels:
if "class" in element.attrs and 'dict-tradmenu' in element['class']:
radio_labels = self.driver.execute_script(f"return arguments[0].shadowRoot.querySelectorAll('label')",
self.soup_to_selenium(element))
filtered_radio = list(
filter(lambda x: label_name.lower().strip() == x.text.lower().strip(),
radio_labels))
if filtered_radio:
[filtered_labels.append(i) for i in filtered_radio]

elif element.get('caption') and label_name.lower() == element.get('caption').lower():
filtered_labels.append(element)

if filtered_labels:
label = self.driver.execute_script(f"return arguments[0].shadowRoot.querySelector('label')", self.soup_to_selenium(filtered_labels))
if len(filtered_labels) > position:
label = filtered_labels[position]

if type(label) == Tag:
label = self.driver.execute_script(f"return arguments[0].shadowRoot.querySelector('label')", self.soup_to_selenium(label))
else:
label = next(iter(self.web_scrap(term=label_name)))

if position > len(filtered_labels):
return self.log_error(f"Element position not found")

else:
labels = container.select("label")
filtered_labels = list(filter(lambda x: label_name.lower() in x.text.lower(), labels))
filtered_labels = list(filter(lambda x: EC.element_to_be_clickable((By.XPATH, xpath_soup(x))), filtered_labels))
label = next(iter(filtered_labels), None)

if not label:
self.log_error("Couldn't find any labels.")
return self.log_error("Couldn't find any labels.")

if type(label) == Tag:
bs_label = self.soup_to_selenium(label)
Expand Down Expand Up @@ -10695,3 +10740,63 @@ def procedure_screen(self, is_procedure_install):
if(stack and not stack.lower() == "teardownclass"):
self.restart_counter += 1
self.log_error(f"Wasn't possible execute parameter_screen() method Exception: {exception}")


def SetCalendar(self, day='', month='', year='', position=0):
"""
:param day: day disered
:type day: str
:param month: month disered
:type month: str
:param year: year disered
:type year: str
:return:
"""

logger().info('Setting date on calendar')

self.wait_blocker()
success = False

self.wait_element(term=".dict-mscalend", scrap_type=enum.ScrapType.CSS_SELECTOR)

endtime = time.time() + self.config.time_out/2
while time.time() < endtime and not success:
calendar = self.web_scrap(term=".dict-mscalend", scrap_type=enum.ScrapType.CSS_SELECTOR)
if calendar:
calendar = calendar[position]
elem_calendar = self.soup_to_selenium(calendar)
# setting year proccess
if year:
year_header = next(iter(self.find_shadow_element('wa-datepicker-year', elem_calendar)))
year_select = next(iter(self.find_shadow_element('select', year_header)))
year_interface = lambda: self.return_selected_combo_value(year_select, locator=True)
self.select_combo(year_select, year, index=True, locator=True)
# setting month proccess
if month:
if int(month) >= 1 and int(month) <= 12:
month = int(month) - 1
month_header = next(iter(self.find_shadow_element('wa-datepicker-month', elem_calendar)))
month_select = next(iter(self.find_shadow_element('select', month_header)))
month_interface = lambda: self.return_selected_combo_value(month_select, locator=True)
month_combo = self.return_combo_object(month_select, locator=True)
month_combo.select_by_index(str(month))
else:
return self.log_error(f"Month {month} doesn't exist")
# setting day proccess
if day:
days_body = next(iter(self.find_shadow_element('wa-datepicker-body', elem_calendar)))
days_elements = self.find_shadow_element('wa-datepicker-day', days_body)
filtered_day = next(iter(list(filter(lambda x: x.get_attribute('day') == day, days_elements))),None)
if filtered_day:
click_try = time.time() + 20
day_selected = lambda: True if filtered_day.get_attribute(
'selected') else False
while not day_selected() and time.time() < click_try:
self.click(filtered_day)
if filtered_day and month_combo and year_interface():
success = filtered_day.get_attribute('day') == day and month_combo.options.index(month_combo.first_selected_option) == month and year_interface() == year
2 changes: 1 addition & 1 deletion tir/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.20.16'
__version__ = '1.20.17'

0 comments on commit a4e9a45

Please sign in to comment.