18. Tracing, Video Diagnostics & Reporting

Recording Traces on Failure

// Start tracing before test:
context.tracing().start(new Tracing.StartOptions()
    .setScreenshots(true)
    .setSnapshots(true)
    .setSources(true));

// In teardown, stop and save only if failed:
if (testFailed) {
context.tracing().stop(new Tracing.StopOptions()
.setPath(Paths.get("target/traces/trace.zip")));
}

View trace in browser:

mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="show-trace target/traces/trace.zip"

Task

  • Implement formatTraceFilename:
  • 1. Accept String testName and int attempt.
  • 2. Return "traces/" + testName + "-attempt-" + attempt + ".zip".
πŸ’‘Common doubts
Did you like the problem?
Lesson 18 of 18
Java
Loading code editor…