diff --git a/selene/core/configuration.py b/selene/core/configuration.py index 54b6ede0..6ad67e69 100644 --- a/selene/core/configuration.py +++ b/selene/core/configuration.py @@ -1390,6 +1390,16 @@ 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.""" + prefix = 'file://' + if os.name == 'nt': # Windows specific + # Replace backslashes with forward slashes and prepend with 'file://' + return f"{prefix}{path.replace(os.sep, '/')}" + else: + # Unix-based paths + return f"{prefix}{path}" + def _generate_filename(self, prefix='', suffix=''): path = self.reports_folder next_id = next(self._counter) @@ -1409,10 +1419,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 +1436,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,