Skip to content

[Feature]: Add option to record traces/screenshots/videos when snapshot tests run with --update-snapshots #39126

@lorenz-gruber-dt

Description

@lorenz-gruber-dt

🚀 Feature Request

Scenario
I'm running visual regression tests in my pipeline with the --update-snapshots flag enabled, so screenshots are automatically updated and can be committed by the pipeline in case they change.

Problem
I would like to record a trace if a test case fails and updates its snapshot. However, since snapshot test cases don't technically fail with --update-snapshots enabled, Playwright doesn't record any traces when using the retain-on-failure mode.

As far as I'm aware my only options at the moment are to either:
A. Use the trace mode on, which isn't ideal since then every test case always records a trace.
B. Run my tests first without the --update-snapshots flag to get a trace for failing test cases, and then run them again with the flag enabled to get updated screenshots. This approach would be better than always recording traces, but it adds unnecessary complexity to the pipeline IMO.

Feature Proposal
My proposal to solve this would be to either:
A. Adapt the retain-on-failure trace mode to also count updating a snapshot as a failure.
B. Introduce a new trace mode, e.g. retain-on-snapshot-change for this specific use case.

Example

In playwright.config.ts:

use: {
  trace: {
    mode: 'retain-on-snapshot-change',
  }
}

Motivation

I think this would be a valid addition to Playwright, as it makes it simpler to set up snapshots tests without requiring complicated workarounds to also leverage tracing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions