From 02b893132a09e3c9b53e16abd1e99821df8c828b Mon Sep 17 00:00:00 2001 From: Edale Miguel Date: Mon, 22 Apr 2024 15:27:11 -0700 Subject: [PATCH 1/2] Update the configuration to log the screenshot and page source file path correctly for all OS types --- selene/core/configuration.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/selene/core/configuration.py b/selene/core/configuration.py index 54b6ede0..daafcea8 100644 --- a/selene/core/configuration.py +++ b/selene/core/configuration.py @@ -1390,6 +1390,15 @@ def with_(self, **options_to_override) -> Config: ) return persistent.replace(self, **options) + def _format_path_as_uri(self, path): + """Converts a local file path to a URI that can be clicked in most editors and browsers.""" + if os.name == 'nt': # Windows specific + # Replace backslashes with forward slashes and prepend with 'file:///' + return f"file:///{path.replace(os.sep, '/')}" + else: + # Unix-based paths + return f"file://{path}" + def _generate_filename(self, prefix='', suffix=''): path = self.reports_folder next_id = next(self._counter) @@ -1409,10 +1418,11 @@ def _inject_screenshot_and_page_source_pre_hooks(self, hook): # or refactor somehow to eliminate all times defining hook fns def save_and_log_screenshot(error: TimeoutException) -> Exception: path = self._save_screenshot_strategy(self) # type: ignore + uri = self._format_path_as_uri(path) return TimeoutException( error.msg + f''' -Screenshot: file://{path}''' +Screenshot: {uri}''' ) def save_and_log_page_source(error: TimeoutException) -> Exception: @@ -1425,7 +1435,8 @@ def save_and_log_page_source(error: TimeoutException) -> Exception: ) path = self._save_page_source_strategy(self, filename) - return TimeoutException(error.msg + f'\nPageSource: file://{path}') + uri = self._format_path_as_uri(path) + return TimeoutException(error.msg + f'\nPageSource: {uri}') return fp.pipe( save_and_log_screenshot if self.save_screenshot_on_failure else None, From f4d74c25e63844d7458c8c960f3e297894815a24 Mon Sep 17 00:00:00 2001 From: cshimm Date: Wed, 24 Apr 2024 11:54:03 -0700 Subject: [PATCH 2/2] prefix variable added. formatted prefix as 'file://' --- selene/core/configuration.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/selene/core/configuration.py b/selene/core/configuration.py index daafcea8..6ad67e69 100644 --- a/selene/core/configuration.py +++ b/selene/core/configuration.py @@ -1392,12 +1392,13 @@ def with_(self, **options_to_override) -> Config: def _format_path_as_uri(self, path): """Converts a local file path to a URI that can be clicked in most editors and browsers.""" + prefix = 'file://' if os.name == 'nt': # Windows specific - # Replace backslashes with forward slashes and prepend with 'file:///' - return f"file:///{path.replace(os.sep, '/')}" + # Replace backslashes with forward slashes and prepend with 'file://' + return f"{prefix}{path.replace(os.sep, '/')}" else: # Unix-based paths - return f"file://{path}" + return f"{prefix}{path}" def _generate_filename(self, prefix='', suffix=''): path = self.reports_folder