How to Record a Video of Selenium Test Scripts Execution ?

As lot of people asking me about the recording feature for selenium web driver scripts. Basically, there is no inbuilt feature in selenium Webdriver for video recording so I did some research and came up with a third party API which provides recording feature and it can be integrated easily with selenium Webdriver.
And it would be really great, if we can capture the videos of our scripts execution as it helps in investigating the real cause of failure.
Let me introduce you all with name of that third party API : ATUTestRecorder

Mouse-Hover
It is a basically a JAR file and you have to include it in our project just like you included selenium JAR file.

How to use ATUTestRecorder API ?

1) Download ATUTestRecorder.

2) Extract the zip file and save the JAR file into your Jars library.

3) Open Eclipse and include this JAR into your project just like you included selenium JAR file.

4) Next step is to use create a program and use this API into our selenium script.

In a program, you have to create an object of ATUTestRecorder class and have to pass below three parameters :

First parameter :
Recording root directory – Provide directory location where videos will be stored.

Second parameter :
Recording name – Provide Recording file name

Third parameter :
isAudioRecordingEnabled – Pass ‘false‘ here.

Below is my JUNIT test in which video recording will be started in the @Before method and once test execution is finished, recording will be stopped in @After method. Lets look at the below code :

Program

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import atu.testrecorder.ATUTestRecorder;
import atu.testrecorder.exceptions.ATUTestRecorderException;

public class ScriptRecordingTest {

    WebDriver driver;
    ATUTestRecorder recorder;

    @Before
    public void setUp() throws Exception {
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
        Date date = new Date();

        //create an object of ATUTestRecorder class and pass 3 parameters explained above.
        recorder = new ATUTestRecorder("C:/Recordings/","Script_Video_" + dateFormat.format(date), false);

        //To start video recording.
        recorder.start();
    }

    @Test
    public void testApp() throws InterruptedException {
        driver = new FirefoxDriver();
        driver.get("http://automate-apps.com/how-to-select-an-option-from-a-drop-down-using-selenium-web-driver/");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        WebElement element = driver.findElement(By.id("month"));
        Select select = new Select(element);
        select.selectByIndex(5);
        Thread.sleep(3000);
        select.selectByVisibleText("Feb");            
    }

    @After
    public void tearDown() throws ATUTestRecorderException {
         //close browser
         driver.quit();
        //Stop the recording
          recorder.stop();
    }

}

When the execution is completed, just go to the directory which you have mentioned during ATUTestRecorder’s object initialization in @before method and you will see a recorded video of your script execution.
If you really like the information provided above, please don’t forget to like us on Facebook, you can also leave the comment.

Leave a Reply

Your email address will not be published. Required fields are marked *