Record a Video of Your TestCases Using Selenium Webdriver+ Java

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

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