From 0692bee3e15ed31d88e41c458ef0a398814ee681 Mon Sep 17 00:00:00 2001 From: 98llm Date: Thu, 28 Nov 2024 14:35:42 -0300 Subject: [PATCH 1/4] fix a selector to icon input --- tir/technologies/poui_internal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tir/technologies/poui_internal.py b/tir/technologies/poui_internal.py index 7d7bdb7d..527ed1ed 100644 --- a/tir/technologies/poui_internal.py +++ b/tir/technologies/poui_internal.py @@ -3439,7 +3439,7 @@ def POSearch(self, content, placeholder): 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): From 258e10557689d776828e6a1403e2925f126a86fe Mon Sep 17 00:00:00 2001 From: renanllisboa Date: Thu, 28 Nov 2024 18:53:46 -0300 Subject: [PATCH 2/4] 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 23475fd75c8efa07cc2247f3d8bbef2bb09d5c3a Mon Sep 17 00:00:00 2001 From: 98llm Date: Fri, 29 Nov 2024 08:50:41 -0300 Subject: [PATCH 3/4] fix posearch on active containers --- tir/technologies/poui_internal.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tir/technologies/poui_internal.py b/tir/technologies/poui_internal.py index 527ed1ed..1f4ada8d 100644 --- a/tir/technologies/poui_internal.py +++ b/tir/technologies/poui_internal.py @@ -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') @@ -3434,7 +3431,7 @@ 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) @@ -3442,6 +3439,7 @@ def POSearch(self, content, placeholder): 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. From cdcf95e1df88649658c5c491c9857e3affdb170e Mon Sep 17 00:00:00 2001 From: renanllisboa Date: Fri, 29 Nov 2024 16:24:37 -0300 Subject: [PATCH 4/4] 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()