Repository navigation
Failure screenshot of a retried test always shows the last attempt #11614
Description
- requires Custom reporters can't access per-attempt details for retries #10303
- related Show the browser trace timeline in test failure output #11592
- introduced by fix(browser): print screenshot path alongside the test error message #5992 (screenshot listed under every attempt's error)
- introduced by feat(browser)!: save failure screenshots in
attachmentsDir#10917 (every attempt overwrites the same file)
Describe the bug
When a browser-mode test fails on every retry, the failure summary prints one error per attempt, and each one lists the same failure screenshot path. Every attempt writes its screenshot to the same file, so only the last attempt's image survives. The screenshot shown under the first attempt's error is actually the last attempt's page.
FAIL |chromium| basic.test.ts > retried
AssertionError: expected 1 to be 10
Failure screenshot:
- .vitest/attachments/failure-screenshots/basic.test.ts/retried.png
⎯⎯⎯[1/3]⎯
FAIL |chromium| basic.test.ts > retried
AssertionError: expected 2 to be 10
Failure screenshot:
- .vitest/attachments/failure-screenshots/basic.test.ts/retried.png
⎯⎯⎯[2/3]⎯
FAIL |chromium| basic.test.ts > retried
AssertionError: expected 3 to be 10
Failure screenshot:
- .vitest/attachments/failure-screenshots/basic.test.ts/retried.png
⎯⎯⎯[3/3]⎯
retried.png shows the attempt 3 button.
There are two parts to this:
- The screenshot file name is derived only from the test name, so each attempt overwrites the previous one. Before feat(browser)!: save failure screenshots in
attachmentsDir#10917, each attempt got its own numbered file (retried-1.png,retried-2.png, ...). - The reporter prints all of the test's failure screenshots under every error, because errors and artifacts don't record which attempt produced them. This has been the case since fix(browser): print screenshot path alongside the test error message #5992 added screenshot paths to the error output. Since feat: store failure screenshots using artifacts API #9588 it has listed one distinct file per attempt, so before feat(browser)!: save failure screenshots in
attachmentsDir#10917 each attempt's image was still among them.
#11232 (for #10303) records each attempt's errors with its retry and repeat index, so the reporter can tell which attempt produced an error. That is enough for the trace timeline from #11592 (#11594), because browser trace artifacts already record retry and repeats. Failure screenshots would still need the artifact to record its attempt in the same way, and a file name per attempt.
Reproduction
import { expect, test } from 'vitest'
import { page } from 'vitest/browser'
let attempt = 0
test('retried', { retry: 2 }, async () => {
attempt++
document.body.innerHTML = `<button>attempt ${attempt}</button>`
await page.getByText(`attempt ${attempt}`).click()
expect(attempt).toBe(10)
})Run with browser mode enabled and screenshotFailures: true (the default).
System Info
Vitest main (b61d1ce), Playwright provider, chromium.
Activity