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

Make available artifacts path in test request #247

Closed
mnovait opened this issue Oct 15, 2024 · 3 comments · Fixed by #248
Closed

Make available artifacts path in test request #247

mnovait opened this issue Oct 15, 2024 · 3 comments · Fixed by #248

Comments

@mnovait
Copy link

mnovait commented Oct 15, 2024

During the execution playwright produces different artifacts such as screenshots, videos or traces.
Some of them are already save and made available in the class ArtifactsRecorder.
I've created this PR to standardize how the plugin saves the paths as class attribute (videos were missing) and to copy in the test request the final result.
The final goal is to have them in the test request, so they can be, for instance, used in the test report or somewhere else in the test flow.

Yes, but we usually start with an issue/feature-request, explain the use-case, elaborate on workarounds etc. Do you mind filing a feature request?

Originally posted by @mxschmitt in #241 (comment)

@mxschmitt
Copy link
Member

Thanks! I'd like to suggest an alternative: providing an output_dir fixture that returns the directory where test files are written. This would also let users write their own files to that location during the test execution (since its unique per test). This matches a request in #227. Since you're already reading from the filesystem, using os.listdir would be needed.

Two questions for implementation:

  1. Which Pytest hook will you use for processing?
  2. Are you planning to upload these somewhere? Videos and tracing files only save on context fixture teardown, if you try to read/process before, you will get corrupted files.

Would this approach work for your needs?

@mnovait
Copy link
Author

mnovait commented Oct 25, 2024

Thanks! I'd like to suggest an alternative: providing an output_dir fixture that returns the directory where test files are written. This would also let users write their own files to that location during the test execution (since its unique per test). This matches a request in #227. Since you're already reading from the filesystem, using os.listdir would be needed.

Two questions for implementation:

1. Which Pytest hook will you use for processing?

you can use pytest_runtest_logreport to run something like:

@pytest.hookimpl(tryfirst=True)
def pytest_runtest_logreport(report):
    if report.failed:
        log_files_message = (
            "it's a failure "
            f"screenshot {screenshot_path_here}"
        )
        if getattr(report.longrepr, "sections", None) is not None:
            report.longrepr.sections.append(
                (
                    "artifacts",
                    log_files_message,
                    "-",
                )
            )
2. Are you planning to upload these somewhere? Videos and tracing files only save on `context` fixture teardown, if you try to read/process before, you will get corrupted files.

what do you mean with upload?
anyway, I'd try to access it only after the execution is ended... do you think that can work?

Would this approach work for your needs?

@mxschmitt
Copy link
Member

Sorry for the late reply - I prototyped #248 - do you mind checking if it would work for you? I also added an example using pytest_runtest_logreport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants