Playwright + Java · Lesson 38 of 38
Module 38: Reporting
Your task
Implement calculatePassRate:
Write it in the editor, then press Check answer (Ctrl + Enter).
// Record videos for failed tests:
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.setRecordVideoDir(Paths.get("videos/"))
.setRecordVideoSize(1280, 720));
Page page = context.newPage();
// Run test...
// Save video path on test failure:
context.close();
System.out.println("Video saved to: " + page.video().path());public class TestResultSummary {
private final int total;
private final int passed;
private final int failed;
public TestResultSummary(int total, int passed, int failed) {
this.total = total;
this.passed = passed;
this.failed = failed;
}
public double getPassRate() {
return total == 0 ? 0 : ((double) passed / total) * 100.0;
}
}In our final module of Playwright with Java, we configure comprehensive test reporting. You will learn to record execution videos, generate clean HTML test summaries, attach screenshots on failure, and analyze test results. Congratulations on reaching the capstone module!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Playwright flushes and finalizes the video file when the BrowserContext is closed. Always close the context before reading page.video().path().
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___