How to record a video in Selenium webdriver?


We can record a video with Selenium. There is no default technique in Selenium to record videos. The videos can be captured in the below processes−

  • ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar files need to be downloaded and saved within the project folder.

  • Next, add the above two jars to the project Build path. Right-click on project−> Click on Properties−> Choose Java Build Path−> Click on the Libraries tab−> Click on Add External Jars−> Browser and select the ATUTestRecorder.jar and ATUReporter_Selenium_testNG.jar−> Click on Apply−> Click OK.

  • Have a folder to hold the videos within the project.

Example

@BeforeMethod
public void bmethod(Method m){
   // format of the date and time defined
   DateFormat d = new SimpleDateFormat("yy−mm−dd HH−mm−ss");
   // get the current date
   Date dt = new Date();
   try {
      // video capture file name
      recorder = new ATUTestRecorder(System.getProperty("userdir") + "\TestVideos\" , m.getName() +       "_" + d.format(dt), false);
   }
   catch (Exception e){
      Log.error("Error capturing videos");
   }
   //begin recording
   try {
      recorder.start();
   }
   catch (Exception e){
      Log.error("Error in beginning videos");
   }
}

Example

@AfterMethod
public void amethod(iTestResult result) {
   try {
      recorder.stop();
   }
   catch (Exception e){
      Log.error("Error in stopping videos");
   }
}

For a Maven project, the pom.xml should have the setting −

Updated on: 28-Nov-2020

582 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements