From 107fb783746810c009fc816fb3da00b406a7fe65 Mon Sep 17 00:00:00 2001 From: naisanzaa Date: Thu, 10 Oct 2024 07:31:25 +0800 Subject: [PATCH] selenium: update logger strings in chrome webdriver --- .../seleniumWrapper/webdriver_chrome.py | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/automon/integrations/seleniumWrapper/webdriver_chrome.py b/automon/integrations/seleniumWrapper/webdriver_chrome.py index 9ecddf96..eac2e955 100644 --- a/automon/integrations/seleniumWrapper/webdriver_chrome.py +++ b/automon/integrations/seleniumWrapper/webdriver_chrome.py @@ -97,9 +97,12 @@ def disable_notifications(self): "prefs", {"profile.default_content_setting_values.notifications": 2} ) - logger.debug(str(dict( - add_experimental_option=("prefs", {"profile.default_content_setting_values.notifications": 2}) - ))) + logger.debug( + f'webdriver :: chrome :: ' + f'disable_notifications :: ' + f'{dict(name="prefs", value={"profile.default_content_setting_values.notifications": 2})}' + ) + return self def disable_sandbox(self): @@ -148,9 +151,12 @@ def enable_notifications(self): self.chrome_options.add_experimental_option( "prefs", {"profile.default_content_setting_values.notifications": 1} ) - logger.debug(str(dict( - add_experimental_option=("prefs", {"profile.default_content_setting_values.notifications": 1}) - ))) + logger.debug( + f'webdriver :: chrome :: ' + f'enable_notifications :: ' + f'{dict(name="prefs", value={"profile.default_content_setting_values.notifications": 1})}' + ) + return self def enable_maximized(self): @@ -168,12 +174,12 @@ def enable_translate(self, native_language: str = 'en'): value=prefs, ) - logger.debug(str(dict( - add_experimental_option=dict( - name="prefs", - value=prefs, - ) - ))) + logger.debug( + f'webdriver :: chrome :: ' + f'enable_translate :: ' + f'{dict(name="prefs", value=prefs)}' + ) + return self def close(self): @@ -181,7 +187,7 @@ def close(self): """ result = self.webdriver.close() - logger.info(f'{result}') + logger.info(f'webdriver :: chrome :: close :: {result}') return result def in_docker(self): @@ -339,12 +345,12 @@ def set_locale_experimental(self, locale: str = 'en-US'): value={'intl.accept_languages': locale} ) - logger.debug(str(dict( - add_experimental_option=dict( - name='prefs', - value={'intl.accept_languages': locale} - ) - ))) + logger.debug( + f'webdriver :: chrome :: ' + f'add_experimental_option :: ' + f'{dict(name='prefs', value={'intl.accept_languages': locale})}' + ) + return self def set_user_agent(self, user_agent: str): @@ -384,12 +390,12 @@ def update_paths(self, path: str): os.environ['PATH'] = f"{os.getenv('PATH')}:{path}" # logger.debug(f'update_paths :: {path=} :: {os.environ['PATH']}') - logger.debug(f'update_paths :: {path}') + logger.debug(f'webdriver :: chrome :: update_paths :: {path}') - logger.info(f'update_paths :: done') + logger.info(f'webdriver :: chrome :: update_paths :: done') return True - logger.error(f'update_paths :: failed :: {path} not found') + logger.error(f'webdriver :: chrome :: update_paths :: failed :: {path} not found') return False def quit(self): @@ -397,7 +403,7 @@ def quit(self): """ result = self.webdriver.quit() - logger.info(f'{result}') + logger.info(f'webdriver :: chrome :: quit :: {result}') return result def quit_gracefully(self): @@ -409,6 +415,6 @@ def quit_gracefully(self): self.quit() self.stop_client() except Exception as error: - logger.error(f'failed to gracefully quit. {error}') + logger.error(f'webdriver :: chrome :: quit :: error :: failed to gracefully quit. {error}') return False return True