You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Add screenshot, video, tracing on/off/on-failure to NUnit/MSTest #2214
Hi Folks,
Merry Christmas to all. I'm wondering if the plan for this feature request is to deliver it as a Christmas gift to all. But if not, do we have an ETA? Last ETA was 1.26 or 1.27. Looks like we are passed that now. Thank you
Just want to add that I use Playwright for automating scenarios other than e2e tests, so if this could be applied in Playwright itself and not Playwright.NUnit it would solve a request from me.
Should I open a different issue or will this be addressed by this one?
Being able to define the trace options via settings file that can be scoped by environment would be a very useful feature here. I guess it's part of a wider feature of being able to define playwright settings similarly to the JS version with environment scoped values. Currently using the .runsettings solution for running locally in VS but for running in CI it would be great to be able to have scoped settings.
Hi, the Playwright bot looked into this on my behalf.
Valid feature request: automatic artifact retention is still missing from the NUnit and MSTest base classes. Screenshot, video, and tracing APIs already exist. The remaining feature is runner integration, not another capture API.
The unresolved contract is what on-failure retains: every failed attempt, even if a retry later passes, or only tests whose final result fails, including setup or cleanup failures? A cleanup hook can use the outcome available then, but cannot know about an exception from a later cleanup. Traces and videos must start recording before the failure. Recording only on a retry captures a different attempt.
The bot reviewed current main and the official runner documentation. This was a source and documentation review only. No builds or tests were run.
The settings parser supports browser, launch, context, assertion timeout, and test ID settings, but has no automatic screenshot, trace, or artifact retention policy:
Console.WriteLine($"Playwright RunSettings Parsing Error: Playwright>{reader.Name} is not implemented");
break;
}
}
. ContextOptions already allows ordinary context options, including video recording, so adding another recording directory setting would not resolve the retention request.
A trace stop without a path explicitly discards the recording:
Lifecycle integration matters on failures. Both BrowserTearDown implementations explicitly close tracked contexts only when their outcome predicate succeeds:
. On other outcomes, worker cleanup disposes services, including the browser. Screenshots and trace export therefore need to happen while their pages and contexts remain usable, with graceful context closure for video.
There is also an open, unmerged MSTest proposal: feat(mstest): add retry-aware failure tracing #3335. It adds opt in failure tracing and retry attachments through TracingOptions, not NUnit support, screenshot or video modes, or a shared settings contract. Its diff was read, but it was not executed or verified as ready to merge.
The full feature also needs a defined artifact destination and attachment policy, unique names for parallel tests and retry attempts, and a clear scope for additional pages and contexts. Existing capture APIs do not decide these runner policies.
Activity
enisak commentedon Aug 29, 2022
Any ETA for this please?
mxschmitt commentedon Aug 29, 2022
enisak we can't give any official eta (but I think we are able to deliver it in 1.27 and maybe 1.26) it's the next thing I'm working on.
markoueis commentedon Dec 23, 2022
Hi Folks,
Merry Christmas to all. I'm wondering if the plan for this feature request is to deliver it as a Christmas gift to all. But if not, do we have an ETA? Last ETA was 1.26 or 1.27. Looks like we are passed that now. Thank you
akamud commentedon Jan 13, 2023
Just want to add that I use Playwright for automating scenarios other than e2e tests, so if this could be applied in Playwright itself and not Playwright.NUnit it would solve a request from me.
Should I open a different issue or will this be addressed by this one?
CameronMackenzie99 commentedon Mar 15, 2023
Being able to define the trace options via settings file that can be scoped by environment would be a very useful feature here. I guess it's part of a wider feature of being able to define playwright settings similarly to the JS version with environment scoped values. Currently using the .runsettings solution for running locally in VS but for running in CI it would be great to be able to have scoped settings.
tesar-tech commentedon Sep 9, 2023
Would you mind to share your current solution for such task?
I have these two ideas:
TheJackGower commentedon Jan 17, 2024
Any ETA for this please? 👍🏻
gauravkhuraana commentedon Feb 29, 2024
I think this feature is already there https://playwright.dev/dotnet/docs/trace-viewer-intro , am i missing anything ?
To do it now.. we are using this workaround
Start the trace always but stop it only if there is a failure or if the flag is set to capture it
DanielHabenicht commentedon Feb 29, 2024
Your link is linking to some other url.
Regarding the question I would say the issue is 70% solved.There ist still no video capture functionality.Sorry misread the issue myself.
This is about adding a functionality to only capture a trace when a test failed.
Probably by repeating the test automatically and capturing the trace then. So there are only traces of failed tests.
gauravkhuraana commentedon Feb 29, 2024
Edited my reply and included the workaround we are using, thanks for pointing the actual ask
philip-reid-MP commentedon Apr 2, 2025
Is there still a plan to introduce this or has it been mothballed?
dcrousso commentedon Oct 21, 2026
Hi, the Playwright bot looked into this on my behalf.
Valid feature request: automatic artifact retention is still missing from the NUnit and MSTest base classes. Screenshot, video, and tracing APIs already exist. The remaining feature is runner integration, not another capture API.
The unresolved contract is what
on-failureretains: every failed attempt, even if a retry later passes, or only tests whose final result fails, including setup or cleanup failures? A cleanup hook can use the outcome available then, but cannot know about an exception from a later cleanup. Traces and videos must start recording before the failure. Recording only on a retry captures a different attempt.For traces today, the official examples show setup and cleanup hooks for both runners: https://playwright.dev/dotnet/docs/trace-viewer-intro#recording-a-trace. Start tracing before the test, then always call
Context.Tracing.StopAsyncduring cleanup. SupplyPathto retain the trace and omit it to discard the trace. This is a manual workaround based on the outcome available at that hook, not a built in retention mode.Source evidence and remaining scope
The bot reviewed current
mainand the official runner documentation. This was a source and documentation review only. No builds or tests were run.playwright-dotnet/src/Playwright.TestAdapter/PlaywrightSettingsXml.cs
Lines 46 to 76 in 9eac4c8
ContextOptionsalready allows ordinary context options, including video recording, so adding another recording directory setting would not resolve the retention request.playwright-dotnet/src/Playwright/Core/Tracing.cs
Lines 146 to 165 in 9eac4c8
ShouldNotThrowWhenStoppingWithoutPathtest exercises this API:playwright-dotnet/src/Playwright.Tests/TracingTests.cs
Lines 246 to 254 in 9eac4c8
Page.ScreenshotAsyncis already available: https://playwright.dev/dotnet/docs/screenshots. A fixture can capture a live page in its derived cleanup hook before the inherited Playwright cleanup closes it. NUnit exposes the outcome throughTestContext.CurrentContext.Result.Outcome.Status, withTestStatus.Failedcovering both assertion failures and errors: https://docs.nunit.org/articles/nunit/writing-tests/TestContext.html#result. Checking onlyResultState.Errorwould miss ordinary assertion failures.RecordVideoDirthroughContextOptions, retain the relevant video references, and explicitly awaitContext.CloseAsyncbefore saving or deleting recordings based on the selected outcome. The documented APIs areVideo.SaveAsAsyncandVideo.DeleteAsync: https://playwright.dev/dotnet/docs/videos and https://playwright.dev/dotnet/docs/api/class-video. Saving or deleting may wait for recording to finish, so awaiting those operations before closing the page or context is not a substitute for finalization.BrowserTearDownimplementations explicitly close tracked contexts only when their outcome predicate succeeds:playwright-dotnet/src/Playwright.NUnit/BrowserTest.cs
Lines 50 to 63 in 9eac4c8
playwright-dotnet/src/Playwright.MSTest/BrowserTest.cs
Lines 51 to 64 in 9eac4c8
TracingOptions, not NUnit support, screenshot or video modes, or a shared settings contract. Its diff was read, but it was not executed or verified as ready to merge.The full feature also needs a defined artifact destination and attachment policy, unique names for parallel tests and retry attempts, and a clear scope for additional pages and contexts. Existing capture APIs do not decide these runner policies.