Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#519] FIX: Fix path of screenshot and pagesource #525

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions selene/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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,
Expand Down
Loading