From 3deae8817546357a33fcf5bc102c0fda8d372d8b Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Fri, 16 Feb 2024 11:11:09 +0530 Subject: [PATCH] test(chart): print error to GH annotation Signed-off-by: Viet Nguyen Duc --- tests/SeleniumTests/__init__.py | 107 +++++++++++++++++++------------- 1 file changed, 63 insertions(+), 44 deletions(-) diff --git a/tests/SeleniumTests/__init__.py b/tests/SeleniumTests/__init__.py index 29b2b7b6c..759fe03d8 100644 --- a/tests/SeleniumTests/__init__.py +++ b/tests/SeleniumTests/__init__.py @@ -89,60 +89,79 @@ def test_download_file(self): self.assertTrue(str(driver.get_downloadable_files()[0]).endswith(file_name)) def tearDown(self): - self.driver.quit() + try: + self.driver.quit() + except Exception as e: + print(f"::error::Exception: {str(e)}") + print(traceback.format_exc()) + raise e class ChromeTests(SeleniumGenericTests): def setUp(self): - options = ChromeOptions() - options.enable_downloads = True - options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') - options.set_capability('se:recordVideo', True) - if SELENIUM_GRID_TEST_HEADLESS: - options.add_argument('--headless=new') - start_time = time.time() - self.driver = webdriver.Remote( - options=options, - command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) - ) - end_time = time.time() - print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") + try: + options = ChromeOptions() + options.enable_downloads = True + options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') + options.set_capability('se:recordVideo', True) + if SELENIUM_GRID_TEST_HEADLESS: + options.add_argument('--headless=new') + start_time = time.time() + self.driver = webdriver.Remote( + options=options, + command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) + ) + end_time = time.time() + print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") + except Exception as e: + print(f"::error::Exception: {str(e)}") + print(traceback.format_exc()) + raise e class EdgeTests(SeleniumGenericTests): def setUp(self): - options = EdgeOptions() - options.enable_downloads = True - options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') - options.set_capability('se:recordVideo', True) - if SELENIUM_GRID_TEST_HEADLESS: - options.add_argument('--headless=new') - start_time = time.time() - self.driver = webdriver.Remote( - options=options, - command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) - ) - end_time = time.time() - print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") - + try: + options = EdgeOptions() + options.enable_downloads = True + options.add_argument('disable-features=DownloadBubble,DownloadBubbleV2') + options.set_capability('se:recordVideo', True) + if SELENIUM_GRID_TEST_HEADLESS: + options.add_argument('--headless=new') + start_time = time.time() + self.driver = webdriver.Remote( + options=options, + command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) + ) + end_time = time.time() + print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") + except Exception as e: + print(f"::error::Exception: {str(e)}") + print(traceback.format_exc()) + raise e class FirefoxTests(SeleniumGenericTests): def setUp(self): - profile = webdriver.FirefoxProfile() - profile.set_preference("browser.download.manager.showWhenStarting", False) - profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "*/*") - options = FirefoxOptions() - options.profile = profile - options.enable_downloads = True - options.set_capability('se:recordVideo', True) - if SELENIUM_GRID_TEST_HEADLESS: - options.add_argument('-headless') - start_time = time.time() - self.driver = webdriver.Remote( - options=options, - command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) - ) - end_time = time.time() - print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") + try: + profile = webdriver.FirefoxProfile() + profile.set_preference("browser.download.manager.showWhenStarting", False) + profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "*/*") + options = FirefoxOptions() + options.profile = profile + options.enable_downloads = True + options.set_capability('se:recordVideo', True) + if SELENIUM_GRID_TEST_HEADLESS: + options.add_argument('-headless') + start_time = time.time() + self.driver = webdriver.Remote( + options=options, + command_executor="%s://%s:%s" % (SELENIUM_GRID_PROTOCOL,SELENIUM_GRID_HOST,SELENIUM_GRID_PORT) + ) + end_time = time.time() + print(f"<< {self._testMethodName} ({self.__class__.__name__}) WebDriver initialization completed in {end_time - start_time} (s)") + except Exception as e: + print(f"::error::Exception: {str(e)}") + print(traceback.format_exc()) + raise e def test_title_and_maximize_window(self): self.driver.get('https://the-internet.herokuapp.com')