How to record Playwright Java test videos is a common question among automation testers who want better visibility into their test runs. Playwright provides a built-in way to capture test execution videos, helping you review every step of your automated flow. In this tutorial, you’ll learn how to enable video recording in Playwright Java, configure options, integrate with your reporting tools, and apply best practices for debugging and analysis.
- Why Use Video Recording in Playwright Java Tests
- Prerequisites and Setup
- Basic Configuration to Record Test Execution Videos in Playwright Java
- Advanced Options and Configuration
- Integrating Video Recording with Test Frameworks and Reporting
- Debugging Tests Using Video Output
- Conclusion
Why Use Video Recording in Playwright Java Tests
Video recording in Playwright Java tests offers more than just visual playback. It helps testers and developers understand exactly what happened during test execution. When a test fails, having a recorded video allows you to visually inspect user interactions, browser actions, and page transitions. This makes it easier to debug issues that logs or screenshots alone might miss.

Using Playwright Java video capture is especially valuable in continuous integration (CI) pipelines. It provides clear visibility into what went wrong without manually re-running tests. Teams can attach these recordings to their test reports, enabling efficient collaboration and faster defect analysis.
Moreover, Playwright Java test reporting with video helps showcase the stability and reliability of automated tests. It is particularly useful for UI-based testing where animations, dynamic elements, or timing-related issues might cause flakiness. By reviewing recorded sessions, you can verify test accuracy and refine your automation strategy with confidence.
Prerequisites and Setup
Before recording videos in your Playwright Java tests, ensure your Playwright environment is properly configured. The setup includes installing Java, Maven, and the Playwright Java library, and configuring your preferred IDE, such as Eclipse.
If you already have Playwright Java installed, you can skip this step and move straight to the configuration section. However, if you are new to Playwright or have not yet set up your environment, follow the complete installation and configuration guide available here:
How to Install Playwright Java with Eclipse and Maven
That detailed article walks you through downloading dependencies, setting up your Maven project, and verifying installation. Once the setup is complete, you will be ready to enable video recording in your Playwright Java tests.
Basic Configuration to Record Test Execution Videos in Playwright Java
Playwright makes it easy to record videos during your test execution. You can enable video recording by configuring the BrowserContext with specific options such as the video directory and resolution. This helps capture each test session automatically, providing a complete playback of your test run.
To start recording, you need to configure the context using Browser.NewContextOptions() with the setRecordVideoDir and setRecordVideoSize methods. The recorded video will be saved in the specified folder once the test completes.
Here’s a simple example showing how to record a test execution video in Playwright Java:
package com.example.test;
import java.nio.file.Paths;
import com.microsoft.playwright.*;
public class VideoRecordingExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
// Set video recording path and size.
Browser.NewContextOptions contextOptions = new Browser.NewContextOptions()
.setRecordVideoDir(Paths.get("videos/")).setRecordVideoSize(1280, 720);
BrowserContext context = browser.newContext(contextOptions);
Page page = context.newPage();
page.navigate("https://google.com");
page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("example.png")));
context.close(); // Video will be saved when context is closed
}
}
}In the above example:
- The
setRecordVideoDirmethod specifies the folder where the videos will be saved. - The
setRecordVideoSizedefines the resolution of the video. - The video is generated once the context is closed, so make sure your code closes it properly at the end of each test.
This basic configuration helps you capture videos for every test run, making it easier to analyze failures and share results visually.
Advanced Options and Configuration
Once you have the basic setup working, you can fine-tune how Playwright handles video recording in your Java tests. This includes controlling when videos are captured, customizing file names, and managing where they are stored.
By default, Playwright records a video for each test when the recordVideoDir option is set. However, you might not always want to save videos for successful runs. To optimize storage and performance, you can record videos only for failed tests. This can be managed easily through your test framework logic, such as in TestNG or JUnit, by conditionally saving videos after checking the test result.
You can also customize your Playwright Java video recording options to change resolution, adjust output paths, or rename videos dynamically. For example, you can include timestamps or test names in the file name for better organization.
Playwright Java video recording options Example
Here’s a slightly advanced setup example:
package com.examples.test;
import com.microsoft.playwright.*;
import java.nio.file.*;
public class AdvancedVideoConfig {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
// Define video directory and resolution
Browser.NewContextOptions contextOptions = new Browser.NewContextOptions()
.setRecordVideoDir(Paths.get("videos/advanced/")).setRecordVideoSize(1920, 1080);
BrowserContext context = browser.newContext(contextOptions);
Page page = context.newPage();
page.navigate("login page URL");
page.fill("#username", "admin");
page.fill("#password", "password123");
page.click("#loginButton");
// Record video and close context
context.close();
// Retrieve video path
Path videoPath = context.pages().get(0).video().path();
System.out.println("Video saved at: " + videoPath);
}
}
}In this configuration:
- The video resolution is set to 1920×1080 for better clarity.
- Videos are saved in a nested folder (
videos/advanced) to maintain structure. - The recorded file path is printed after execution to confirm where the video is saved.
If you want to generate video for Playwright Java tests with customized file names (for example, by test name), you can use your framework’s test method name to rename the video file after context closure. This helps in maintaining better traceability when multiple tests are executed.
These advanced configurations allow you to make video recording more efficient and better suited to your reporting needs.
Integrating Video Recording with Test Frameworks and Reporting
Recording videos is most effective when integrated with your test framework and reporting system. By combining Playwright Java video recording with tools like TestNG or JUnit, you can automatically attach recorded videos to your test reports. This improves traceability, especially when reviewing failed tests or demonstrating automated workflows.
In a TestNG setup, you can use the @AfterMethod annotation to handle video files after each test run. For example, you can move or rename the recorded video files based on the test name or result (pass or fail). This makes it easier to associate each video with a specific test case in your report.
Playwright Video Recording With TestNG Example
Here’s a sample integration example using TestNG:
package com.examples.test;
import com.microsoft.playwright.*;
import org.testng.annotations.*;
import java.nio.file.*;
public class VideoIntegrationTest {
Playwright playwright;
Browser browser;
BrowserContext context;
Page page;
@BeforeMethod
public void setup() {
playwright = Playwright.create();
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
context = browser.newContext(new Browser.NewContextOptions().setRecordVideoDir(Paths.get("videos/testng/"))
.setRecordVideoSize(1280, 720));
page = context.newPage();
}
@Test
public void sampleLoginTest() {
page.navigate("https://bing.com");
}
@AfterMethod
public void tearDown() {
// Get video before closing the context
if (!context.pages().isEmpty()) {
Page recordedPage = context.pages().get(0);
Path videoPath = recordedPage.video().path();
System.out.println("Video path: " + videoPath);
} else {
System.out.println("No pages found to record video.");
}
context.close();
browser.close();
playwright.close();
}
}This setup allows you to capture a video for each test run automatically. The videos are saved once the browser context closes and can be linked to your reports for easy access.

You can also integrate Playwright Java video recording for tests into custom HTML or extent reports by embedding video links directly in the test report output. This gives you an interactive reporting experience where you can replay test execution right from the report itself.
In continuous integration pipelines such as Jenkins or GitHub Actions, recorded videos can be uploaded as build artifacts. This makes them easily accessible for review when a test fails. It not only improves debugging but also provides better visualization of your automated test runs, enhancing overall transparency and confidence in your test suite.
By adding video links to your reports, you transform plain test results into complete Playwright Java test reporting with video, enabling quick diagnosis and faster issue resolution.
Debugging Tests Using Video Output
Recorded videos play a key role in debugging Playwright Java tests with video. They allow you to visually trace each step of your automation, making it much easier to understand what happened before a failure occurred. Unlike logs or stack traces, videos show the real user interactions, such as clicks, typing, scrolling, and page transitions, which help identify the exact cause of test failures.
For instance, if a test fails because of a timing issue or flaky behavior, you can replay the recorded video to confirm whether an element was visible, clickable, or loaded at the right time. Similarly, for UI glitches such as overlapping elements, missing buttons, or layout shifts, video playback helps you pinpoint rendering problems that might not appear in screenshots.
Another common use case is detecting environment-related issues. Sometimes, tests fail due to network delays, server-side errors, or slow page responses. Watching the recorded video makes it clear whether the failure was due to the test script or an external factor like network instability or browser lag.
When analyzing videos, here are a few helpful tips:
- Playback speed: Slow down or speed up the playback to focus on specific interactions.
- Timestamp analysis: Compare the time of failure in logs with the video timeline to isolate the issue.
- Video storage: Organize recorded videos by test name or timestamp to easily locate relevant recordings later.
- Error validation: Use the video in combination with test logs and screenshots to verify expected versus actual behavior.
By combining video evidence with your test results, you can quickly identify root causes, reduce debugging time, and ensure more stable Playwright Java test runs.
Conclusion
Being able to record test execution videos in Playwright Java brings immense value to your automation process. It allows you to visually confirm what happened during a test run, especially when dealing with failed scenarios or flaky tests. The ability to review Playwright Java screen recordings for automation improves transparency, speeds up debugging, and enhances overall test reliability.
By integrating video recording into your Playwright Java framework, you can quickly detect UI glitches, identify timing issues, and create richer test reports with clear visual evidence.
Start capturing your test execution videos today and make your Playwright Java automation framework more robust, insightful, and easier to maintain.