Selenium Record Video

Profile picture for user arilio666

In this article, we will see how we can record our test performance in selenium using a simple tool called  monte screen recorder.

1.) Setup

<!-- -->
  • Paste this dependency in the POM.xml file.
  • This will install the necessary jars related to the screen recorder in our project.

2.) Utility code

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.monte.screenrecorder.ScreenRecorder;
import static*;
import static*;
public class ScreenRecorderUtil extends ScreenRecorder {
public static ScreenRecorder screenRecorder;
public String name;
public ScreenRecorderUtil(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat,
  Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder, String name)
    throws IOException, AWTException {
 super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat, movieFolder); = name;
protected File createMovieFile(Format fileFormat) throws IOException {
 if (!movieFolder.exists()) {
 } else if (!movieFolder.isDirectory()) {
  throw new IOException("\"" + movieFolder + "\" is not a directory.");
 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
 return new File(movieFolder,
   name + "-" + dateFormat.format(new Date()) + "." + Registry.getInstance().getExtension(fileFormat));
public static void startRecord(String methodName) throws Exception {
 File file = new File("./test-recordings/");
 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 int width = screenSize.width;
 int height = screenSize.height;
 Rectangle captureSize = new Rectangle(0, 0, width, height);
 GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
 screenRecorder = new ScreenRecorderUtil(GC, captureSize,
   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, 24, FrameRateKey,
     Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
   new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),
   null, file, methodName);
public static void stopRecord() throws Exception {
  • Save this as and save it into the package folder where the tests are located.

3.) Test

  • Use the start record and pass in the method we run the test within it.
  • Make sure to stop the record at the end.
  • After running the test, refresh the project.
  • We can see here the video files in avi format are generated after a successful test run.