Creating a video capture of your Selenium tests using Monte Screen Recorder

In previous posts, I have shown you how to include screen shots in your HTML test reports to help you in debugging tests and identifying the cause of test failures. However, in certain cases, a video showing exact screen states, screen transitions and input as generated by your tests might come in even more handy. This goes expecially when your tests run unattended. Such a video could also help presenting / demonstrating your work to your peers and other stakeholders.

Last week I stumbled upon Monte Screen Recorder, a Java library that can assist you in creating these video captures of your Selenium tests. In this relatively short post, I will show you how to create such a video capture.

Installation and configuration of the Monte Screen Recorder is easy. Simply download the .jar file from here, add it as a dependency to your project and you’re all set.

However, please note that using Monte Screen Recorder, as well as playing back the screen captures afterwards, requires the TechSmith Screen Capture Codec (TSCC) to be installed.

To create a screen capture, all we need to do create a new instance of the ScreenRecorder object with the settings we would like to use. For example:

private static void startRecording() throws Exception {

	// set the graphics configuration
	GraphicsConfiguration gc = GraphicsEnvironment
			.getLocalGraphicsEnvironment()
			.getDefaultScreenDevice()
			.getDefaultConfiguration();
		
	// initialize the screen recorder:
	// - default graphics configuration
	// - full screen recording
	// - record in AVI format
	// - 15 frames per second
	// - black mouse pointer
	// - no audio
	// - save capture to predefined location
		
	screenRecorder = new ScreenRecorder(gc,
			gc.getBounds(),
			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,
			new File(targetFolder));
	screenRecorder.start();
}

As you can see, Monte Screen Recorder offers a lot of settings and options you can tweak to create the perfect screen capture. I’ve chosen a frame rate of 15fps as this is enough to see what’s happening in my test (a simple login / logout script) and it keeps the file size reasonably small. Also, I’ve chosen to not capture audio, but you can easily choose otherwise.

After you started recording using screenRecorder.start(), you can execute any Selenium test you like without the need for additional changes. After test execution is finished, you simply stop recording using screenRecorder.stop().

You can watch or download a screen capture I’ve made using Monte Screen Recorder and the settings shown in the code snippet above by clicking here. Again, please note that playback requires the TSCC codec. It takes about five seconds before the actual test starts, probably because of my laptop being a bit slow.

I found the Monte Screen Recorder to be very easy to use and a option worth checking out for everybody looking to capture execution of his / her Selenium tests.

48 thoughts on “Creating a video capture of your Selenium tests using Monte Screen Recorder

  1. Hi Bas,

    This is a nice post that helps a lot of automation testers to capture their automated stuff.

    Is there any option that allows us to rename and save it in required path? If so please guide me in doing that. So I can name the videos test wise.

    Thanks a lot!

    • Hi Mahesh,

      I’m not sure to be honest. I think the ScreenRecorder constructor only lets you specify a target folder, right? And no explicit file name?

      What happens if you specify a filename instead of just the folder? It’s a File object parameter judging from the documentation so that might just work. If not, you’ll have to do some extra work after the screen capture has been created. You can for example monitor the directory for files of a certain type that have been created/modified after a certain date and rename those (this should be your video file) to the desired filename.

      • Hi Bas,

        I did try the way you suggested(adding the file name to the path), but the program considered the name as the folder name and created one.

        Looks link we didn’t have an option to set the file name for the video created.

        Thanks a lot for suggesting the alternate to do it with minimal effort.

        Reagrds,
        Mahesh

  2. Hey Bas,

    I am impressed with your effort.

    Is there any way that we can give user defined file name?

    Is there any way that we can create less file size with other video format.

    Thanks,
    Lakshmi

    • Hey Lakshmi,

      No I don’t think you can specify a different file name, but to be sure you should check the API.

      I can’t check the site from here but I think other file formats are supported. Maybe there’s another setting that would reduce the file size. You could also play around with frame rates lower than 15.

    • Hey Attila,

      I found an example here. See line 199 in the code in that example and replace the null in the ScreenRecorder constructor in my example with that.

      • It doesn’t work unfortunatelly.
        (environment: Win10, IntelliJ, selenium with Chrome driver)
        The code creates less than 1MB video file. When I play this video file, the player writes to me:
        Unidentified codec:
        VLC could not identify the audio or video codec

        So it seems, it’s not a good solution.
        Is there any other way?
        I would like to screen recording with the computer sound.

  3. this code is working fine but when i want to play the video its giving me a error like this..(.Windows Media Player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file.)To avoid this i have also installed (media codec),but still it is not working.please help me as soon as possible.

  4. yes Bas i have installed TSC2 Codec and EnSharpen® windows codec from your given link,i am using windows 7,64 bit,but still can not play the video.after installing the codec is there any more steps that i should follow.please help me Bas..

  5. getting error at MediaTypeKey
    CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
    DepthKey, 24, FrameRateKey, Rational.valueOf(15),

  6. How to record parallel execution of testcase i,e one in chrome and another in IE browser using monte or any other java based tool. Can you p lease suggest me on this.

  7. HI bass

    same solution to player videos on html with mp4 or similar extensions aceptance in browsers?

    • I have no idea to be honest, I’ve never written a line of PHP in my life.

      Well, that’s not entirely true, but I wouldn’t know anyway.

  8. Hi Bas,
    its recording fine but need to record audio from mic so whats the input we go for .
    And also need a target folder to save the video.
    String targetFolder = (“C://”);
    //this.files = new TreeSet();
    screenRecorder = new ScreenRecorder(gc, new Format(
    MediaTypeKey, MediaType.FILE, MimeTypeKey, FormatKeys.MIME_QUICKTIME),
    new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,
    VideoFormatKeys.ENCODING_QUICKTIME_ANIMATION,
    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);
    screenRecorder.start();

    This have been added in my code and how can i remove the watermark from the video.

    • new ScreenRecorder(gc, new Format(
      MediaTypeKey, MediaType.FILE, MimeTypeKey, FormatKeys.MIME_QUICKTIME),
      new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,
      VideoFormatKeys.ENCODING_QUICKTIME_ANIMATION,
      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)), new Format(MediaTypeKey, MediaType.AUDIO,
      EncodingKey, ENCODING_QUICKTIME_TWOS_PCM,
      FrameRateKey, new Rational(48000, 1),
      SampleSizeInBitsKey, 16,
      ChannelsKey, 2, SampleRateKey, new Rational(48000, 1),
      SignedKey, true, ByteOrderKey, ByteOrder.BIG_ENDIAN))

      Added sound but its too bad :)……

  9. Hi Bas:

    First of all, thanks for this post.

    I want to call the public static void function from another class, so I took your example for this, but I have a java.lang.NullPointerException when I use the stop method.

    public static void endRecording(InternetExplorerDriver driver)throws Exception{

    screenRecorder.stop();
    }

    This is the line which calls the method from the other class:

    Video.endRecording((InternetExplorerDriver)driver);

    Could you please help me?

    • Hey Rodrigo,

      that’s probably because the screenRecorder object is null there. A quick and dirty fix would be to initialize that in the calling class and simply pass it as an extra argument. Or look at dependency injection to solve it in a more elegant manner.

      • Hi Bas:

        Thanks so much!!!

        I have another question:

        Is it possible save the video if the script fails before the screenRecorder.stop(); method?

        Thanks in advance.

        • I don’t know, but if you put the screenRecorder.stop() call in an @AfterX method, it is guaranteed to execute even if test execution fails, so your video should be saved regardless of the result of your test run.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.