From 258e10557689d776828e6a1403e2925f126a86fe Mon Sep 17 00:00:00 2001 From: renanllisboa Date: Thu, 28 Nov 2024 18:53:46 -0300 Subject: [PATCH 1/2] change coverage to check by layer instead of string --- tir/technologies/webapp_internal.py | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tir/technologies/webapp_internal.py b/tir/technologies/webapp_internal.py index ee04d1fe..62d16b6f 100644 --- a/tir/technologies/webapp_internal.py +++ b/tir/technologies/webapp_internal.py @@ -3335,31 +3335,34 @@ 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" + current_zindex = 0 + coverage_finished = False 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() + logger().debug("Startin coverage.") - 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) + while time.time() < endtime and not coverage_finished: - if element: - self.SetButton(self.language.finish) - text_cover = self.WaitShow(string, timeout=10, throw_error=False) - if text_cover: - logger().debug(string) + 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 current_zindex < self.return_last_zindex(): + current_zindex = self.return_last_zindex() + self.SetButton(self.language.finish) logger().debug("Waiting for coverage to finish.") - self.WaitHide(string, throw_error=False) - logger().debug("Finished coverage.") + + coverage_finished = current_zindex >= self.return_last_zindex() + + if coverage_finished: + logger().debug("Coverage finished.") + + time.sleep(1) else: endtime = time.time() + self.config.time_out @@ -9466,7 +9469,7 @@ 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 ) From cdcf95e1df88649658c5c491c9857e3affdb170e Mon Sep 17 00:00:00 2001 From: renanllisboa Date: Fri, 29 Nov 2024 16:24:37 -0300 Subject: [PATCH 2/2] adding get_coverage method and more time added count_time decorator. --- tir/technologies/webapp_internal.py | 117 ++++++++++++++-------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/tir/technologies/webapp_internal.py b/tir/technologies/webapp_internal.py index 62d16b6f..747ec106 100644 --- a/tir/technologies/webapp_internal.py +++ b/tir/technologies/webapp_internal.py @@ -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. @@ -3335,35 +3347,9 @@ def Finish(self): >>> oHelper.Finish() """ element = None - timeout = 900 - optional_term = "wa-button" if self.webapp_shadowroot() else "button, .thbutton" - current_zindex = 0 - coverage_finished = False if self.config.coverage: - endtime = time.time() + timeout - - logger().debug("Startin coverage.") - - while time.time() < endtime and not coverage_finished: - - 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 current_zindex < self.return_last_zindex(): - current_zindex = self.return_last_zindex() - self.SetButton(self.language.finish) - logger().debug("Waiting for coverage to finish.") - - coverage_finished = current_zindex >= self.return_last_zindex() - - if coverage_finished: - logger().debug("Coverage finished.") - - time.sleep(1) - + self.get_coverage() else: endtime = time.time() + self.config.time_out while( time.time() < endtime and not element ): @@ -3378,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] @@ -3413,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 ): @@ -9476,9 +9482,6 @@ def TearDown(self): 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()