Selenium Record Video with JUnit in Java

In this example we show you how you can record a video of selenium test cases in java. This way you can watch how your selenium tests are performing. If you sun your selenium tests on a selenium grid like sauce labs or browser stack, they provide taking screenshots or making video’s. This tutorial focuses on recording video of selenium tests locally.

Maven Dependencies

<!-- junit testing -->
<!-- selenium -->
<!-- screen recorder -->

Selenium Record Video Example

package com.memorynotfound.test;

import org.junit.*;
import org.monte.screenrecorder.ScreenRecorder;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import static*;
import static*;
import java.awt.*;
import java.util.List;

public class ScreenRecorderTest {

    private static WebDriver driver;
    private static ScreenRecorder screenRecorder;

    public static void setUp() throws IOException, AWTException {

        //Create a instance of GraphicsConfiguration to get the Graphics configuration
        //of the Screen. This is needed for ScreenRecorder class.
        GraphicsConfiguration gc = GraphicsEnvironment

        //Create a instance of ScreenRecorder with the required configurations
        screenRecorder = new ScreenRecorder(gc,
                new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
                new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                        CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                        DepthKey, (int)24, FrameRateKey, Rational.valueOf(15),
                        QualityKey, 1.0f,
                        KeyFrameIntervalKey, (int) (15 * 60)),
                new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,"black",
                        FrameRateKey, Rational.valueOf(30)),

        // create driver
        driver = new FirefoxDriver();

        // maximize screen

    public void beforeTest() throws IOException {

    public void testScreenRecorder() {

    public void afterTest() throws IOException {
        List<File> createdMovieFiles = screenRecorder.getCreatedMovieFiles();
        for(File movie : createdMovieFiles){
            System.out.println("New movie created: " + movie.getAbsolutePath());

    public static void cleanUp(){
        if (driver != null) {


Example output

New movie created: /var/folders/ts/tv2s4k357c79jmw4_rkbt7b40000gn/T/screenrecorder/ScreenRecording 2015-02-07 at 16.55.53.avi

Example Video

Here is an example of a recorded video: Selenium Record Video Example. It is a small video of 3 seconds that opens a web page.



You may also like...