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(“[email protected]”);
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.
Where we can see the recorded videos i.e where those videos will be stored ?
Kindly help
Thanks in advance
Regards
Praveen A
LikeLike
It will store in C:\Users\user\Videos
else you can search in the ‘Start-Menu’ just type “ScreenRecording”
LikeLike
I have downloaded MonteMedia and added all the Jars….but
LikeLike
Is this screen recording or browser session recorder. Will this work when we run tests in parallel?
LikeLike
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…!
LikeLike
Video is not being recorded if the test case is failed. A blank file is being created in case of failed scenarios
LikeLike
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.
LikeLike
for successful Recording you have to stop recorder add screenRecorder.stop() in after method it will work.
LikeLike
This piece of code really helped. Thank you :)
LikeLiked by 1 person
is there any what to capture every browser session ? to use it when we run tests in parallel
LikeLike
is there a way to capture a browser session ?, to use it when we run tests in parallel .
LikeLike
Generally, this script captures the actions which was going on your desktop. It captures everything you see. So, if your script is to test parallel then it should capture all the actions performed.
LikeLike
i understand , but i don`t want to do this i want to record every browser session it may be 10 browsers at the same time , is there a way to record every browser session ??
LikeLike
No, that’s not possible. I would suggest you to integrate with Browserstack or saucelabs. That will record all the sessions being performed.
Check this out
https://seleniumbycharan.wordpress.com/2015/11/16/compatibility-testing-using-browserstack-selenium-testng/
LikeLike
Try below solution for Screen Recording during Mobile Automation (Appium)
http://easytestautomation.blogspot.in/2016/06/easy-to-record-screen-in-appium-for.html
LikeLike
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
LikeLike
Please share the exception you’ve faced
LikeLike
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.
LikeLike
I have tried this code but its not working,can any one help m to record my test case using selinium.
LikeLike
Please let me know the exception you’re facing
LikeLike
Does it work for tests cases running in parallel?
LikeLike
You may not get individual recording on Parallel execution. It will record everything which is on Focus
LikeLike
Also, does it work with Selenium RemoteWebDriver?
LikeLike
Yes, it works on remote as well
LikeLike
Hi, This is very excellent topic. Is it possible to record the screen when browser is running in headless mode. Also, do you have code for c#
LikeLike
I have a situation am not using the jar but rather a pom.xml, I have added the dependencies. I am . new to automation was looking for something like this, although my test is not running parallel but my setup is slightly different from your’s. Do you have a private email I can send you an email to please
LikeLike
Hi Hari ,
I have used the Monte and recording is working fine.
But also i have added the audio to record during the screen recording time but the audio is loaded as distorted one.
So have you checked it about the audio.
This is my code.Can you please provide some help.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
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.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 static org.monte.media.AudioFormatKeys.ENCODING_QUICKTIME_TWOS_PCM;
import static org.monte.media.AudioFormatKeys.SampleSizeInBitsKey;
import static org.monte.media.AudioFormatKeys.ChannelsKey;
import static org.monte.media.AudioFormatKeys.ByteOrderKey;
import static org.monte.media.AudioFormatKeys.SignedKey;
import static org.monte.media.AudioFormatKeys.SampleRateKey;
import java.nio.ByteOrder;
import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.monte.media.Format;
import org.monte.media.FormatKeys;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.VideoFormatKeys;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
public class CallChrome {
private static ScreenRecorder screenRecorder;
public static void main(String[] args) throws IOException, AWTException, InterruptedException {
// TODO Auto-generated method stub
GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();
// initialize the screen recorder:
String targetFolder = (“C://”);
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)), 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));
screenRecorder.start();
Thread.sleep(10000);
screenRecorder.stop();
System.out.println(“Stopped”);
}
}
LikeLike
I think you should try some other tool, this article has to be modified as it is outdated
LikeLike