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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Expose output_dir as a fixture #227

Open
red8888 opened this issue May 14, 2024 · 3 comments
Open

[Feature]: Expose output_dir as a fixture #227

red8888 opened this issue May 14, 2024 · 3 comments

Comments

@red8888
Copy link

red8888 commented May 14, 2024

馃殌 Feature Request

I could not find how to get a handle to the names playwright generates for its output folders under "test-results". I would think the browser context or something would have a property I could access to get the dynamically generated test-results/<TEST_NAME_SANITIZED>/trace.zip

I want to colocate browser trace json files in the same folder with the playwright trace files. The problem is I can't find docs on how playwright sanitizes and generates the test specific folders- I also don't want to have to duplicate that code myself just so I can do this:

browser_context.start_tracing(
    page=page,
    screenshots=True,
    path=<Path under test-results where the trace.zip will be located>,
)

I don't want to try to generate <Path under test-results where the trace.zip will be located> myself.

How do I control the naming of these folders OR get a handle to their paths from playwright? Seems like this feature does not exist right?

Example

No response

Motivation

I want to colocate browser trace json files in the same folder with the playwright trace files so my test results aren't scattered around everywhere.

@mxschmitt
Copy link
Member

which trace.json file do you want to add?

The code is currently not exposed, but we could maybe expose it, so its something like we do upstream in Node.js - like output_dir:

def _build_artifact_test_folder(
pytestconfig: Any, request: pytest.FixtureRequest, folder_or_file_name: str
) -> str:
output_dir = pytestconfig.getoption("--output")
return os.path.join(
output_dir,
truncate_file_name(slugify(request.node.nodeid)),
truncate_file_name(folder_or_file_name),
)

You could probably import the function from your test as a workaround for now.

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python May 14, 2024
@red8888
Copy link
Author

red8888 commented May 16, 2024

@mxschmitt I just want to add my browser traces I enable with cdp. It would be great to make full trace output folder path an attribute of the context object.

Can I assume that truncate_file_name is public facing because of the lack of _ lol

from slugify import slugify
from pytest_playwright.pytest_playwright import truncate_file_name

PYTEST_PLAYWRIGHT_DEFAULT_OUTPUT_DIR = "test-results"

folder = f"{PYTEST_PLAYWRIGHT_DEFAULT_OUTPUT_DIR}/{truncate_file_name(slugify(request.node.nodeid))}"

@mxschmitt
Copy link
Member

Can I assume that truncate_file_name is public facing because of the lack of _ lol

Its more public by accident. If we were to expose output_dir, then as a fixture. I'd recommend to import _build_artifact_test_folder for now until we expose that feature. If you are interested in creating a PR to expose the fixture, happy to merge.

@mxschmitt mxschmitt changed the title [Feature]: Colocate browser trace json files in the same folder as the playwright trace files- or provide a handle to trace.zip location [Feature]: Expose output_dir May 21, 2024
@mxschmitt mxschmitt changed the title [Feature]: Expose output_dir [Feature]: Expose output_dir fixture May 21, 2024
@mxschmitt mxschmitt changed the title [Feature]: Expose output_dir fixture [Feature]: Expose output_dir as a fixture May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants