In Java, we can extend Selenium WebDriver test scripts to record videos by using an open source tool named Monte Media Library.
In this blog we will look at how to configure and use the Monte Media Library’s ScreenRecorder class with Selenium, to record movies of tests.
ScreenRecoder supports the AVI and QuickTime formats for recording movies. The program provides multiple configurations for colors, mouse cursor, screen refresh rate, mouse rate, audio, and so on.
First step is to download the ScreenRecorder.jar file from the site or search  the net for it.
Second step is to add the ScreenRecorder.jar file to the project’s build path.
Here is a sample code on how to integrate video recording to Selenium WebDriver test:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.monte.screenrecorder.ScreenRecorder;
import static*;
import static*;
import org.junit.*;

import java.awt.*;

public class videoRecording {

private WebDriver driver;
private ScreenRecorder screenRecorder;

public void setUp() throws Exception {
// Create an 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_QUICKTIME),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,ENCODING_QUICKTIME_JPEG, CompressorNameKey,
ENCODING_QUICKTIME_JPEG, 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 a new instance of the Firefox driver
driver = new FirefoxDriver();
// Call the start method of ScreenRecorder to begin recording

public void testGoogleSearch() throws Exception {

WebElement element = driver.findElement("q"));
// Enter something to search for


public void tearDown() throws Exception {
// Close the browser
// Call the stop method of ScreenRecorder to end the recording

During the video recording of desktop, the ScreenRecorder class needs the graphics configuration of the display screen on which tests are executed.
Java’s AWT package has a class named GraphicsConfiguration through which we can pass this information to the ScreenRecorder class.

The graphics configuration details from the GraphicsEnvironment class of AWT are collected in the GraphicsConfiguration gc.
This will get configuration of the default system display screen for an instance of GraphicsConfiguration.

The ScreenRecorder constructor is supplied with the following parameters:
1, GraphicsConfiguration (gc) – Provides display screen information such as size, resolution, and so on.
2, Video and compression format (video/avi, tscc) – The output format of the movie, encoding mechanism, color depth, frames per second, keyframe interval.
ScreenRecorder supports AVI and QuickTime movie formats.
(In our case we use QuickTime movie format).
3, Color of the mouse cursor and refresh rate (black, 30) – The color of the mouse cursor and refresh rate.
4, Audio format (null) – No audio will be recorded.

Video recording is invoked by calling the ScreenRecorder’s start() method and completed by calling the ScreenRecorder’s stop() method.
When a recording is finished, ScreenRecorder stores the output file in the user’s Home directory. On Windows, it will save the recorded file in the C:\Users\<username>\Videos folder.

Posted By István Lackó

    17 Responses to “Recording videos of tests in Java”

  1. a says:

    Have you ever thought about creating an e-book or guest authoring on other sites?

    I have a blog centered on the same subjects you discuss and would really like to have
    you share some stories/information. I know my viewers would appreciate your work.
    If you’re even remotely interested, feel free to shoot me an e-mail.

  2. Aldo says:

    I tried your code and it worked like a charm (thanks!). However, when I tried to run it on a Virtual Machine, the video was completely black. Do you have any idea why this happened? Any workaround?


    • Hi!
      It seems that this is some driver/codec issue. Be sure that every necessary file is installed in the virtual machine, or try to update them.

      • S says:

        I’ve had a similar problem , wanted to record the tests while they are run against Jenkins or even Virtual Machine.

        Any hints would be a great help as you how to make it work rather than a black screen.

  3. harender says:

    Hello sir,
    Can you please tell how to record audio with it also.

  4. Vishnu says:

    Dear Folks,

    How to specify the video file to store instead of storing in the c:// driver.

    • Hi,

      There is a constructor which can be used for your situation:
      ScreenRecorder(java.awt.GraphicsConfiguration cfg, java.awt.Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat, movieFolder)

      Check this URL for: (java.awt.GraphicsConfiguration, java.awt.Rectangle,,,,,

      According to javadoc, you have two additional parameters here:

      Here is an example:

      ScreenRecorder screenRecorder = new ScreenRecorder(gc, 
      				new Rectangle(new Dimension(1920, 1080)),
      				new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_QUICKTIME),
      				new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,ENCODING_QUICKTIME_JPEG, CompressorNameKey,
      ENCODING_QUICKTIME_JPEG, DepthKey, (int) 24,FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f,KeyFrameIntervalKey, (int) (15 * 60)),
      				new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, &quot;black&quot;, FrameRateKey,Rational.valueOf(30)),
      				new File(&quot;&lt;Your file path&gt;&quot;));
  5. Rajashekar says:

    i am able to record the test by using your code.
    but how we can record the test for mobile automation ?

  6. Raju says:


    In my case, even browser also not opening and i’m not getting any errors also. Please provide your comments.

    • Hi!
      Thanks for your comment on our blog. Here is some suggestions in this situation:

      make sure that you have the latest Selenium framework (2.46.0) (
      if you have multiple instances of Java Virtual Machine, make sure that you are use the same for your eclipse project and for your Selenium Webdriver.
      if you are using Firefox to start your test, make sure that you have version 37.0.2 or higher
      if you are using Chrome to start your test, make sure that you have your ChromeDriver executable on your hard drive, and that you added it to path variable. (

  7. Uday says:


    Thanks for the nice article.

    Is there a way to improve the quality of the video? What parameters/values i need to update in the above code?

    Another point is, is there a way i can provide the video file name rather than ScreenRecorder generated timpstamp name?


  8. Amar Sorathiya says:

    I am getting blank video while running script on Jenkins.

    Any help would be appreciated.

  9. Amar Sorathiya says:

    I am getting blank video while running script on Jenkins.
    Please help if anyone has any idea….

  10. Umesh says:

    Try below solution for Screen Recording during Mobile Automation (Appium)

  11. vedant says:

    Thanks,this code is working but the file is recorded in .mov ,so i can not play the video.Suggest me so that i can play the recorded video,or can i record it in some different format.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>