[Feature]: retain trace for first failure only, not including retries
🚀 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:
- a test fails on the first try
- the test tries to clean up after itself, but separately fails to do so
- 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-retrybecause it captures the original failure rather than a side effect of the original failure -
retain-on-failurebecause it saves space
I would be happy to implement this myself; I'll just wait a few days for feedback or a green light.