Skip to content

Commit

Permalink
Merge pull request #1605 from totvs/release/v1.20.28rc6
Browse files Browse the repository at this point in the history
Release/v1.20.28rc6
  • Loading branch information
renanllisboa authored Nov 29, 2024
2 parents fa84111 + 92d1413 commit 012de7d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 64 deletions.
16 changes: 7 additions & 9 deletions tir/technologies/poui_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,14 +3413,11 @@ def POSearch(self, content, placeholder):
self.wait_element(term='po-page')
endtime = time.time() + self.config.time_out
while (not element and time.time() < endtime):
po_page = next(iter(
self.web_scrap(term="[class='po-page']", scrap_type=enum.ScrapType.CSS_SELECTOR,
main_container='body')),
None)

po_page = next(iter(self.web_scrap(term="[class='po-page']", scrap_type=enum.ScrapType.CSS_SELECTOR,
main_container='body')),None)
if po_page:
page_list = next(iter(po_page.find_all_next('div', 'po-page-list-filter-wrapper')), None)

page_list = po_page.find_all_next('div', 'po-page-list-filter-wrapper')
page_list = next(iter(list(filter(lambda x: self.element_is_displayed(x), page_list))),None)
if page_list:
input = page_list.select('input')

Expand All @@ -3434,14 +3431,15 @@ def POSearch(self, content, placeholder):

if not element:
self.log_error("Couldn't find element")

self.switch_to_iframe()
element().clear()
element().send_keys(content)

action = lambda: self.soup_to_selenium(next(iter(po_page.select('po-icon'))))
action = lambda: self.soup_to_selenium(next(iter(input.parent.select('po-icon'))))
ActionChains(self.driver).move_to_element(action()).click().perform()


def ClickTable(self, first_column, second_column, first_content, second_content, table_number, itens, click_cell, checkbox):
"""
Clicks on the Table of POUI component.
Expand Down
116 changes: 61 additions & 55 deletions tir/technologies/webapp_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
from tir.technologies.core.logging_config import logger
from tir.technologies.core.base_database import BaseDatabase

def count_time(func):
"""
Decorator to count the time spent in a function.
"""
def wrapper(*args, **kwargs):
starttime = time.time()
result = func(*args, **kwargs)
endtime = time.time()
logger().debug(f"Time spent in {func.__name__}: {endtime - starttime}")
return result
return wrapper

class WebappInternal(Base):
"""
Internal implementation of Protheus Webapp class.
Expand Down Expand Up @@ -3335,32 +3347,9 @@ def Finish(self):
>>> oHelper.Finish()
"""
element = None
text_cover = None
string = self.language.codecoverage #"Aguarde... Coletando informacoes de cobertura de codigo."
timeout = 900
optional_term = "wa-button" if self.webapp_shadowroot() else "button, .thbutton"

if self.config.coverage:
endtime = time.time() + timeout

while((time.time() < endtime) and (not element or not text_cover)):

ActionChains(self.driver).key_down(Keys.CONTROL).perform()
ActionChains(self.driver).key_down('q').perform()
ActionChains(self.driver).key_up(Keys.CONTROL).perform()

element = self.wait_element_timeout(term=self.language.finish, scrap_type=enum.ScrapType.MIXED,
optional_term=optional_term, timeout=5, step=1, main_container="body", check_error = False)

if element:
self.SetButton(self.language.finish)
text_cover = self.WaitShow(string, timeout=10, throw_error=False)
if text_cover:
logger().debug(string)
logger().debug("Waiting for coverage to finish.")
self.WaitHide(string, throw_error=False)
logger().debug("Finished coverage.")

self.get_coverage()
else:
endtime = time.time() + self.config.time_out
while( time.time() < endtime and not element ):
Expand All @@ -3375,6 +3364,52 @@ def Finish(self):
if not element:
logger().warning("Warning method finish use driver.refresh. element not found")

@count_time
def get_coverage(self):

timeout = 1800
optional_term = "wa-button" if self.webapp_shadowroot() else "button, .thbutton"
current_layers = 0
coverage_finished = False
element = None
new_modal = False
coverage_exceed_timeout = False

endtime = time.time() + timeout

logger().debug("Startin coverage.")

while not coverage_finished:

if time.time() > endtime:

if coverage_exceed_timeout:
logger().debug("Coverage exceed timeout.")
break

logger().debug("Coverage exceed default timeout. adding more time.")
endtime = time.time() + timeout
coverage_exceed_timeout = True

if not element:
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('q').key_up(Keys.CONTROL).perform()
element = self.wait_element_timeout(term=self.language.finish, scrap_type=enum.ScrapType.MIXED,
optional_term=optional_term, timeout=5, step=1, main_container="body", check_error=False)

if element and not new_modal:
current_layers = self.check_layers('wa-dialog')
self.SetButton(self.language.finish)
new_modal = current_layers + 1 == self.check_layers('wa-dialog')
logger().debug("Waiting for coverage to finish.")

if new_modal:
coverage_finished = current_layers >= self.check_layers('wa-dialog')

if coverage_finished:
logger().debug("Coverage finished.")

time.sleep(1)

def click_button_finish(self, click_counter=None):
"""
[internal]
Expand Down Expand Up @@ -3410,35 +3445,9 @@ def LogOff(self):
>>> oHelper.LogOff()
"""
element = None
text_cover = None
string = self.language.codecoverage #"Aguarde... Coletando informacoes de cobertura de codigo."
timeout = 900
click_counter = 1

if self.config.coverage:
endtime = time.time() + timeout

while((time.time() < endtime) and (not element or not text_cover)):

ActionChains(self.driver).key_down(Keys.CONTROL).perform()
ActionChains(self.driver).key_down('q').perform()
ActionChains(self.driver).key_up(Keys.CONTROL).perform()

element = self.wait_element_timeout(term=self.language.logOff, scrap_type=enum.ScrapType.MIXED,
optional_term=".tsay", timeout=5, step=1, main_container="body", check_error = False)

if element:
if self.click_button_logoff(click_counter):
text_cover = self.search_text(selector=".tsay", text=string)
if text_cover:
logger().info(string)
timeout = endtime - time.time()
if timeout > 0:
self.wait_element_timeout(term=string, scrap_type=enum.ScrapType.MIXED,
optional_term=".tsay", timeout=timeout, step=0.1, main_container="body", check_error = False)
click_counter += 1
if click_counter > 3:
click_counter = 1
self.get_coverage()
else:
endtime = time.time() + self.config.time_out
while( time.time() < endtime and not element ):
Expand Down Expand Up @@ -9466,16 +9475,13 @@ def TearDown(self):
endtime = time.time() + self.config.time_out
while (time.time() < endtime and (
not self.element_exists(term=term, scrap_type=enum.ScrapType.CSS_SELECTOR, main_container="body"))):
self.close_warning_screen()
self.close_screen_before_menu()
self.Finish()
elif not webdriver_exception:
self.SetupTSS(self.config.initial_program, self.config.environment )
self.SetButton(self.language.exit)
self.SetButton(self.language.yes)

if (self.search_text(selector=".tsay", text=string) and not webdriver_exception):
self.WaitProcessing(string, timeout)

if len(self.log.table_rows[1:]) > 0 and not self.log.has_csv_condition():
self.log.save_file()

Expand Down

0 comments on commit 012de7d

Please sign in to comment.