How To Record Selenium WebDriver Test Execution Video

If you can record full video for your selenium test execution automatically then It can be great feature for you. I think many of you are already aware about HOW TO CAPTURE SCREENSHOT of web page during test execution In selenium. Very only few people will be aware
about video recording of screen for selenium script. Webdriver do not have any built In facility to record video but we need to use some external services to record video.

Why video recording of selenium test?
Supposing you have a selenium script which takes 1 or more hours to complete the execution. So If you can record full test execution screen video then It will helps you to debug Issue more easily If any Issue arise In between. Also you can use recorded videos as a proof to show test execution activities to your client or manager.

Steps to record video for webdriver test execution

We need to ATUtestrecorder jar file download and then use it to record selenium test execution videos.

Step 1 : Download ATUTestRecorder jar file

  1. Download Location : You can ATUTestRecorder jar file download from THIS PAGE. Click on ATUTestRecorder_2.1.zip link.
  2. Alternate ATUTestRecorder jar file Download Location : You can download It from THIS LOCATION too.
Both above links will provide you "ATUTestRecorder_2.1.zip" file to download. Download It and extract It. Thrre will be "ATUTestRecorder_2.1.jar" file In extracted folder.

Step 2 : Add "ATUTestRecorder_2.1.jar" In your project's build path

Add "ATUTestRecorder_2.1.jar" file In your project's build path. You can refer "Adding jar Files In Project's Build Path" section on THIS PAGE If you don't know how to add It.

Step 3 : Create folder to store recorded videos.
You need to create folder "ScriptVideos" In your D: drive. We will use this folder to store recorded videos.

Now we are ready to record videos for test execution.

Steps 4 : Create and run test

Create and run bellow given test In eclipse. As you see In bellow given script, video recording will be started In beginning because code to start video recording Is Inside @BeforeTest method. Video recording will stop at end of test because code to stop recording Is Inside @AfterTest annotation method.

package Testing_Pack;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import atu.testrecorder.ATUTestRecorder;

public class RecordTest {
 
 WebDriver driver;
 ATUTestRecorder recorder;

 @BeforeTest
 public void setup() throws Exception {
  DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH-mm-ss");
  Date date = new Date();
  //Created object of ATUTestRecorder
  //Provide path to store videos and file name format.
  recorder = new ATUTestRecorder("D:\\ScriptVideos\\","TestVideo-"+dateFormat.format(date),false);
  //To start video recording.
  recorder.start();  
  driver = new FirefoxDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  driver.get("http://google.com/");
 }

 @Test
 public void getScrollStatus() throws Exception {  
  driver.manage().window().setSize(new Dimension(400,768));
  Thread.sleep(2000);  
  
  driver.manage().window().setSize(new Dimension(400,400));
  Thread.sleep(2000);
  
  driver.manage().window().setSize(new Dimension(1024,400));      
 } 
 
 @AfterTest
 public void Close() throws Exception {
  driver.quit();
  //To stop video recording.
  recorder.stop();;
 }
}

At the end of test execution, Go to "D:\ScriptVideos" folder. There will be created .mov file. You can play It to see recorded video.

25 comments:

  1. This is a great posting! Will this work with Cucumber Java's Before and After hooks when running webdriver scenarios from Eclipse?

    Thank you!

    Mike

    ReplyDelete
  2. This is working like a charm. Thank you very much for this code.

    ReplyDelete
  3. will this work with perl and how should I configure it.

    Thanks,

    ReplyDelete
  4. Hi,
    Iam getting Error in the path place
    ATUTestRecorder recorder = new ATUTestRecorder("D:\\D Drive\\SeleniumPractice\\","TestVideo-",+dateFormat.format(date),false);

    +dateFormat.format(date);+operator is undefined for the string.Please let me know what mistake i did

    ReplyDelete
    Replies
    1. sorround with try catch or add throws declaration.

      Delete
  5. Hi Arvind,

    The 2 videos (*.mov) are saved with above 18 mb and 5mb, but when i tried to play them in VLC , its just blank black screen, not able to play them in windows media player. please need your help .

    ReplyDelete
    Replies
    1. Hi Balu,

      The ATUrecord records the screen in .MOV format which is Apple's default format for screen recording. for watching these recordings just download Apple's genuine QuickTime player from there official site. Or please find link here - https://secure-appldnld.apple.com/QuickTime/031-43075-20160107-C0844134-B3CD-11E5-B1C0-43CA8D551951/QuickTimeInstaller.exe

      Delete
  6. Hi Arvind,

    The 2 videos (*.mov) are saved with above 18 mb and 5mb, but when i tried to play them in VLC , its just blank black screen, not able to play them in windows media player.

    ReplyDelete
  7. Superb This is something new to me in Selenium Thanks a ton. really works very fine.

    ReplyDelete
  8. It works well
    Just note that you're missing code line in //Created object of ATUTestRecorder
    you are Not object creation

    ReplyDelete
  9. Hi All -

    Checked above video captures and it work well. However, have a concern, this works similar to monte recorder i.e. of windows recording, but what if we need to record on webdriver browser, if so this will be recorded even on remote/virtual machines.

    This current given above solutions shows black screen when executed over remote/virtual machines.

    Looking forward.

    Thanks,
    Santti
    sbhinge@scan-it.com.sg

    ReplyDelete
  10. hi,
    it couldnt play on windows media player.....
    please give me solution on that

    ReplyDelete
  11. Did anyone got success to record the video on VMs remote machine

    ReplyDelete
  12. when we are running a script for more than 30 or 35 mins it is generating a file of size in Gb, which is worried some for the codes having long runs, can we reduce the size of these generated video files either by reducing the resolution or any other means
    please help me on this

    ReplyDelete
  13. Hi All,

    For the script which takes more than 30 mins, it is generating a video file in Gb, can we reduce the size of the generated video file either by reducing the resolution or any other means.

    Looking forward for your valueble reply.

    thanks,
    Roshan

    ReplyDelete
  14. How will you include test method name in the recorder = new ATUTestRecorder("D:\\ScriptVideos\\","TestVideo-"+dateFormat.format(date),false); line ? for more detailed logging and can be helpful in debugging purposes ???

    ReplyDelete
  15. can we do other activities parallely while video is recorded?

    ReplyDelete
  16. Is it necessary to have D:\\ drive? can i use this jar in E:\\ or F:\\ drive ?

    ReplyDelete
  17. this will not help for scenarios, when you have multiple tests running in parallel on same machine. any thoughts?

    ReplyDelete
  18. Thank you very much.
    This is working like a charm.
    Awesome

    ReplyDelete
  19. Good stuff. What if we are using this in different method as a parameter. What should be the object type??

    ReplyDelete
  20. Does this have a maven dependency

    ReplyDelete
  21. Hi
    I have added audio to monte jar but the quality is very bad.
    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));



    Is there any solution to improve the quality

    ReplyDelete
  22. Hi Arvind,
    Is there any way to record the screen in the headless mode?

    ReplyDelete