Search

Monday, February 9, 2015

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 will use ATU Test Recorder to record selenium test execution videos.

Step 1 : Download ATUTestRecorder jar file

  1. Download Location : You can download It from THIS PAGE. Click on ATUTestRecorder_2.1.zip link.
  2. Alternate 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.

No comments:

Post a Comment