playwright-java
playwright-java copied to clipboard
[Feature]: Allow automatic saving of trace files
🚀 Feature Request
This is also kind of a bug but I decided to make it a feature request.
Feature Request: I would like the ability to automatically save trace files.
Bug: I cannot save trace file based on test status.
Example
An option in OptionsFactory
that allows the user to configure when to save trace files off
, on
, retain-on-failure
and an option for a root trace directory. The fixtures would then automatically start the trace, and depending on the option and the test result, would save the trace files in the root trace directory.
Motivation
As I said, this is a feature request/bug report. I think the benefits are clear but the bug needs to be explained.
Currently, the user can only save a trace file by doing something like this:
@AfterEach
void afterEach(BrowserContext browserContext) {
// save trace file
}
There is no way for the user to only save trace files if the test fails (retain-on-failure
). JUnit recommends implementing the TestWatcher interface. The problem is that the test watcher methods are called after the AfterEachCallback
methods, so when the test watcher method is called, the BrowserContext
is already closed by the BrowserContextExtension
. So even if I use reflection to get at the BrowserContext
inside my TestWatcher
, an exception is thrown.
If we allow the fixtures to handle traces this issue can be easily solved