Record a Video of Your TestCases Using Selenium Webdriver+ Java


images (3)

We know how to capture a screenshot of your Automated TestCases, How about a video ?? This post helps you to record your screen when you conduct automation test. This is very simple to record/video test cases.It also helps you to debug if any test script went wrong.

Please follow the steps to record your screen

Step 1. You have to download the MonteScreenRecorder.jar from Here.

Step 2. Extract it and add jar to buildpath under your project Also add your selenium required jars. Step 3. Prepare your test cases which needs to be automated.

Step 4. Need to call “screenRecorder.start()” methods at starting of your test scripts and “screenRecorder.stop()” at the end of execution. Just follow the below code for the reference.

import static org.monte.media.FormatKeys.EncodingKey;
import static org.monte.media.FormatKeys.FrameRateKey;
import static org.monte.media.FormatKeys.KeyFrameIntervalKey;
import static org.monte.media.FormatKeys.MIME_AVI;
import static org.monte.media.FormatKeys.MediaTypeKey;
import static org.monte.media.FormatKeys.MimeTypeKey;
import static org.monte.media.VideoFormatKeys.CompressorNameKey;
import static org.monte.media.VideoFormatKeys.DepthKey;
import static org.monte.media.VideoFormatKeys.ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE;
import static org.monte.media.VideoFormatKeys.QualityKey;

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;

import org.monte.media.Format;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class VideoRecorderclass {
public ScreenRecorder screenRecorder;
WebDriver driver;
@Test
public void test01() throws Exception {
VideoRecorderclass videoRecord = new VideoRecorderclass();

videoRecord.startRecording(); //Started recording
driver=new FirefoxDriver();
driver.get(“https://accounts.google.com”);
driver.findElement(
By.xpath(“//input[@id=’Passwd’]/preceding-sibling::input[@id=’Email’]”))
.sendKeys(“DOLLAR@GMAIL”);
Robot r= new Robot();
r.mouseWheel(4);
driver.findElement(By.xpath(“//input[contains(@id,’Passwd’)]”)).sendKeys(“PASSWORD”);

System.out.println(“Password was typed”);
Thread.sleep(2000);

videoRecord.stopRecording(); //Stopped recording

}
public void startRecording() throws Exception
{
GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();

this.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, 24, FrameRateKey, Rational.valueOf(15),
QualityKey, 1.0f,
KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, “black”,
FrameRateKey, Rational.valueOf(30)),
null);
this.screenRecorder.start();
}

public void stopRecording() throws Exception
{
this.screenRecorder.stop();
}
}

That’s it. You will see the video file in your C drive mostly..!  You can play it using VLC player.

Advertisements

23 thoughts on “Record a Video of Your TestCases Using Selenium Webdriver+ Java

  1. Praveen Ambi July 15, 2015 / 11:48 am

    Where we can see the recorded videos i.e where those videos will be stored ?
    Kindly help

    Thanks in advance
    Regards
    Praveen A

    Like

    • charan163 July 15, 2015 / 2:31 pm

      It will store in C:\Users\user\Videos
      else you can search in the ‘Start-Menu’ just type “ScreenRecording”

      Like

      • Anonymous June 13, 2016 / 1:05 pm

        I have downloaded MonteMedia and added all the Jars….but

        Like

  2. Rajendra kumar July 15, 2015 / 10:28 pm

    Is this screen recording or browser session recorder. Will this work when we run tests in parallel?

    Like

    • charan163 July 15, 2015 / 11:02 pm

      It will just record your screen.What ever happens while automating,it will capture all the gesture including mouse hovering actions.And also moves of cursor…!

      Like

  3. Mithilesh July 19, 2015 / 1:02 pm

    Video is not being recorded if the test case is failed. A blank file is being created in case of failed scenarios

    Like

    • charan163 July 19, 2015 / 4:50 pm

      No, The code doesnt work in that way.It will record everything.Code dont even know which are the passed testcases and which are the failed testcases.Maybe your logic went wrong.

      Like

  4. Anonymous March 4, 2016 / 6:46 am

    This piece of code really helped. Thank you :)

    Liked by 1 person

  5. Deeb Andrawis Andrawis April 20, 2016 / 3:38 pm

    is there any what to capture every browser session ? to use it when we run tests in parallel

    Like

  6. Anonymous June 13, 2016 / 1:09 pm

    I have downloaded MonteMedia and added all the Jar files into my project, but I am getting The method startRecording() is undefined for the type when I mouse hover the startRecording.
    ex: VideoRecorderclass videoRecord = new VideoRecorderclass();
    videoRecord.startRecording(); //Started recording

    Like

  7. Krunal September 6, 2016 / 6:14 pm

    Its very Good.
    I have tried this MonteScreenRecorder and its working fine on my machine.
    But I want to record client machine screen where test cases execute.
    So is there any other way with that I can record client machine screen.

    Like

  8. Anonymous February 21, 2017 / 4:05 pm

    I have tried this code but its not working,can any one help m to record my test case using selinium.

    Like

    • Hari Charan February 21, 2017 / 5:42 pm

      Please let me know the exception you’re facing

      Like

  9. Marco Sanabria Alfaro April 20, 2017 / 10:05 am

    Does it work for tests cases running in parallel?

    Like

    • Hari Charan April 20, 2017 / 2:59 pm

      You may not get individual recording on Parallel execution. It will record everything which is on Focus

      Like

  10. Marco Sanabria Alfaro April 20, 2017 / 10:06 am

    Also, does it work with Selenium RemoteWebDriver?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s