Repository navigation
fix(tracing): resolve relative HAR and trace paths against current cwd - #3363
Open
Hossein Rahimi (HoosseinRahimi) wants to merge 1 commit into
Open
Hossein Rahimi (HoosseinRahimi) wants to merge 1 commit into
Hossein Rahimi (HoosseinRahimi) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
The Playwright driver runs as a separate process, so relative paths passed to tracing.stop() / stop_chunk() and to record_har_path were resolved against the driver process's working directory instead of the Python client's current directory. If the cwd changes after the browser is launched (common in tests and job runners), trace and HAR files silently land in the wrong place. Resolve such paths to absolute paths on the Python side before they reach the driver, mirroring what Artifact.save_as() already does. Fixes microsoft#3361
Author
|
@microsoft-github-policy-service agree |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Relative paths passed to
tracing.stop(path=...),tracing.stop_chunk(path=...)andrecord_har_path=...were resolved by the driver process, not the Python client. Since the driver starts before the test/runner may change its working directory, the artifacts silently landed in the wrong place when the cwd changed after browser launch — the exact scenario in #3361.This PR resolves such paths to absolute paths on the Python side before they reach the driver, mirroring what
Artifact.save_as()already does for page screenshots/PDFs.Changes
playwright/_impl/tracing.py_absolute_path()helper that normalizes a path withos.path.abspath(os.fspath(path))(same approach asArtifact.save_as())._record_into_har(): normalize the HAR output path._save_chunk(): normalize the trace file path before it is sent to the driver or passed to local utils.Test
Added
test_TR_043_should_resolve_relative_trace_and_har_paths_against_current_directory, which:monkeypatch.chdir) to a temp dir,Verified locally on Windows / Python 3.13:
relative-trace.zipandrelative.harare created in the driver's working directory (the repo root), not the temp dir.Fixes #3361