Skip to content

Commit

Permalink
Merge pull request #1604 from totvs/hotfix/webapp_internal_coverage
Browse files Browse the repository at this point in the history
Hotfix/webapp internal coverage
  • Loading branch information
renanllisboa authored Nov 29, 2024
2 parents 6e77644 + cdcf95e commit 92d1413
Showing 1 changed file with 61 additions and 55 deletions.
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 92d1413

Please sign in to comment.