Skip to content

Add Start Tracing / Stop Tracing / Start Trace Chunk / Stop Trace Chunk keywords for ad-hoc tracing #5122

Description

@Snooz82

Use case

Today tracing is all-or-nothing: it can only be enabled for a whole context via the tracing argument of New Context, producing one trace for everything that context ever did. Users debugging a single flaky test case, or wanting a small shareable trace of just one scenario, cannot start tracing mid-test, cannot stop it early, cannot give the trace a human-readable title for the trace viewer, and cannot include source files. The only workaround is restructuring suites so that the interesting steps run in their own dedicated context — invasive and often impossible.

Playwright's Tracing API supports exactly this: start/stop on demand, plus chunks — multiple separate trace files recorded within one tracing session, each covering only the actions between startChunk and stopChunk.

Proposed keyword / arguments

Start Tracing    *, screenshots=True    snapshots=True    sources=False    title=None    name=None    live=False
Stop Tracing    path=None
Start Trace Chunk    *, title=None    name=None
Stop Trace Chunk    path=None
  • Start Tracing (Setter) begins tracing on the current context. title names the trace in the trace viewer; sources=True embeds source files; live enables live-viewable traces; name prefixes intermediate trace files in the traces dir.
  • Stop Tracing (Getter) stops tracing, saves the zip to path (default: a generated file under the library's output directory) and returns the file path.
  • Start Trace Chunk / Stop Trace Chunk record only the actions in between into a separate trace file within the same tracing session, so one long-lived context can yield one small trace per scenario.
New Context
Start Tracing    title=Login flow    sources=True
Go To    ${LOGIN_URL}
Start Trace Chunk    title=Submit credentials
Fill Text    id=user    alice
Click    id=submit
${chunk}=    Stop Trace Chunk    path=${OUTPUT_DIR}/traces/login-submit.zip
${trace}=    Stop Tracing    path=${OUTPUT_DIR}/traces/login-full.zip

Playwright API

Implementation notes

  • protobuf/playwright.proto: RPCs for start/stop/startChunk/stopChunk with the option fields.
  • node/playwright-wrapper: calls on the current context's tracing object; must coexist with the existing New Context tracing= mechanism (guard against double-start with a clear error). Note the library already wraps every keyword in tracing.group internally — chunk boundaries slot into that unchanged.
  • Python: keywords in Browser/keywords (natural fit: playwright_state.py or a new tracing module), docs, stub regen; atest verifying a valid trace zip is produced mid-context and that chunks contain only their own actions.

Backwards compatibility

Purely additive: four new keywords. The existing New Context tracing= shortcut keeps working unchanged; starting tracing twice is an explicit error rather than a behavior change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions