Skip to content

feat: retain-on-failure-and-retries trace option#39387

Merged
dgozman merged 3 commits intomicrosoft:mainfrom
Yuvalmorami:feat/retain-on-failure-and-retries
Mar 2, 2026
Merged

feat: retain-on-failure-and-retries trace option#39387
dgozman merged 3 commits intomicrosoft:mainfrom
Yuvalmorami:feat/retain-on-failure-and-retries

Conversation

@Yuvalmorami
Copy link
Copy Markdown
Contributor

@Yuvalmorami Yuvalmorami commented Feb 24, 2026

Closes #34588

Summary

Adds a new retain-on-failure-and-retries trace mode that records traces for every test attempt (initial run + retries) and retains all of them when any attempt fails. This makes it possible to compare failing and passing runs side-by-side when debugging flaky tests.

Behavior

  • Test passes on first try (no retries) → trace discarded (same as retain-on-failure)
  • Test fails then passes on retry (flaky) → both traces retained
  • Test fails on all attempts → all traces retained

Changes

  • packages/playwright/src/worker/testTracing.ts — Always capture trace; abandon only if test passed on first try (retry=0)
  • packages/playwright/src/program.ts — Add to CLI modes list
  • utils/generate_types/overrides-test.d.ts / packages/playwright/types/test.d.ts — Add to TraceMode union
  • docs/src/test-api/class-testoptions.md / docs/src/test-cli-js.md — Document the new mode
  • tests/playwright-test/playwright.trace.spec.ts — Tests for flaky, passing, and always-failing scenarios
  • tests/playwright-test/playwright.artifacts.spec.ts — Artifact layout test with retries

@Yuvalmorami
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

expect(fs.existsSync(retryTracePath)).toBeTruthy();
});

test('trace:retain-on-failure-and-retries should not create trace if test passes', async ({ runInlineTest }, testInfo) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this test, this case is already covered by test(trace:${mode} should not create trace zip artifact if page test passed above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it :)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 2, 2026

Test results for "tests 1"

5 flaky ⚠️ [chromium-library] › library/popup.spec.ts:260 › should not throw when click closes popup `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1080 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-page] › page/page-wait-for-function.spec.ts:104 › should work with strict CSP policy `@firefox-ubuntu-22.04-node20`
⚠️ [webkit-library] › library/video.spec.ts:452 › screencast › should scale frames down to the requested size `@webkit-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:118 › should collapse repeated console messages for test `@macos-latest-node20`

38683 passed, 841 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 2, 2026

Test results for "MCP"

1 failed
❌ [firefox] › mcp/cli-session.spec.ts:22 › list @mcp-macos-15

5132 passed, 171 skipped


Merge workflow run.

@dgozman
Copy link
Copy Markdown
Collaborator

dgozman commented Mar 2, 2026

Thank you for the contribution!

@dgozman dgozman merged commit c0554cb into microsoft:main Mar 2, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: No option to keep all traces from a failing test

3 participants