playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: retain trace for first failure only, not including retries

Open JacobCrofts opened this issue 1 year ago • 0 comments

🚀 Feature Request

I would like to add a new option for trace recording: on-first-failure. This would record and retain a trace only during the first failure of a given test, not during retries.

Related but different: https://github.com/microsoft/playwright/issues/13797

Example

import { defineConfig } from '@playwright/test';
export default defineConfig({
  retries: 1,
  use: {
    // if a test fails, it will retry once, but a trace will only be collected for the first failure
    trace: 'on-first-failure',
  },
});

Motivation

My team uses Playwright for end-to-end tests that cause state modifications within our app. In theory, our tests "clean up" after themselves after each test completes, or fails, but implementing such functionality perfectly is difficult, especially for longer tests that fail in between two state changes.

We have run into issues like the following:

  1. a test fails on the first try
  2. the test tries to clean up after itself, but separately fails to do so
  3. the test fails on the first retry as a side effect of the failed cleanup step

The option I am suggesting would be preferable to:

  • on-first-retry because it captures the original failure rather than a side effect of the original failure
  • retain-on-failure because it saves space

I would be happy to implement this myself; I'll just wait a few days for feedback or a green light.

JacobCrofts avatar Feb 16 '24 17:02 JacobCrofts