Skip to content

Tracing temp directories are never cleaned up when keywords are called from Python outside a Robot Framework run #5153

Description

@aaltat

Tracing writes its working files to browser/traces/temp/<uuid>/ (Browser/keywords/playwright_state.py:911). Those are cleaned up from the _start_suite listener hook (Browser/browser.py:838-848), which only fires during a Robot Framework run. When keywords are called directly from Python the hook never runs, so the temp directories accumulate and are never removed.

Reproduce

from Browser import Browser

browser = Browser()
browser.new_browser("webkit", headless=True)
browser.new_context(tracing=True)
browser.new_page("https://robotframework-browser.org")
browser.close_context()
browser.close_browser("ALL")

Observed afterwards, left in place:

browser/traces/temp/<uuid>/
    <name>.trace
    <name>.network
    resources/*.jpeg

The trace zip itself is produced correctly by close_context(); it is only the temp working directory that is left behind, once per traced context.

Note that with the default outputdir these land inside the installed package rather than the caller's working directory — that part is a separate issue about the relative default outputdir, and it is filed on its own. This report is about the cleanup never happening at all, which remains true even when outputdir is absolute.

Suggested fix

Remove the temp directory when the trace is flushed in close_context(), rather than relying on a listener hook that only exists during a Robot Framework run.

Environment

Browser 20.3.0, Robot Framework 7.4.1, Python 3.14.7, macOS, webkit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions