Skip to content

[BUG] Tracing does not work with playwright.request.newcontext() #137

Closed as not planned

Description

@jnjgomez10

Context:
I am using playwright to test REST API endpoints.
I do not see trace.zip after I run pytest --tracing=on.

Code Snippet

Simple test script

import os
from typing import Generator

import pytest
from playwright.sync_api import Playwright, APIRequestContext


@pytest.fixture(scope="session")
def api_request_context(
    playwright: Playwright,
) -> Generator[APIRequestContext, None, None]:
    request_context = playwright.request.new_context(
        base_url="https://api.publicapis.org",
        ignore_https_errors=True
    )
    yield request_context
    request_context.dispose()

def test_should_create_bug_report(api_request_context: APIRequestContext) -> None:
    response = api_request_context.get("/entries")
    assert response.ok

Describe the bug

pytest --tracing=on test_mytest.py does not produce trace.zip

Activity

  1. QuLogic commented on Nov 4, 2022

    @QuLogic

    AFAICT, it also doesn't work with Browser.new_context (e.g., using the browser fixture to create a context with a different scale factor browser.new_context(device_scale_factor=2)); not sure if that ends up using the same APIRequestContext in the end.

    Edit: Ah, maybe what I'm seeing is #99.

  2. guandalf commented on Feb 20, 2024

    @guandalf

    And this is particularly problematic as the only way to test chrome extensions is by creating a new context as per https://playwright.dev/python/docs/chrome-extensions

    Please help :)

  3. guandalf commented on Feb 20, 2024

    @guandalf

    In fact I just reimplemented my fixture copying it from

    and creating the context the way I need it and everything worked as expected. Might not help in all cases but to me it kinda solved....

  4. ltsuda commented on Oct 9, 2024

    @ltsuda

    I've found the same issue, if this is not by design.

    It appears that we should use fixture new_context, so tracing/videos/screenshots are taken automatically if enabled but new_context is a function fixture and not session.

    #232
    #216

  5. shisrafilov commented on Oct 24, 2024

    @shisrafilov

    The issue is still there

  6. added 2 commits that reference this issue on Oct 8, 2026
    57a0d4b
    80d7569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions