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
	// 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,
			new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
			new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, 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 File(targetFolder));

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.