Saturday, March 9, 2019

Screen recording of a test execution in selenium using JAVA

1. Download .jar from https://www.randelshofer.ch/monte/index.html

add to your project














2.Create class and copy below code into the class


 package learning;  
 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.AWTException;  
 import java.awt.GraphicsConfiguration;  
 import java.awt.GraphicsEnvironment;  
 import java.io.IOException;  
 import org.monte.media.Format;  
 import org.monte.media.FormatKeys.MediaType;  
 import org.monte.media.math.Rational;  
 import org.monte.screenrecorder.ScreenRecorder;  
 public class Video {  
      static ScreenRecorder screenRecorder;  
      // Method to start recording video  
      public static void startRecord() throws IOException, AWTException {  
           GraphicsConfiguration configuration = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()  
                     .getDefaultConfiguration();  
           screenRecorder = new ScreenRecorder(configuration,  
                     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, (int) 24, FrameRateKey,  
                               Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, (int) (15 * 60)),  
                     new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),  
                     null);  
           screenRecorder.start();  
      }  
      // Method to stop vedeo recording  
      public static void stopRecord() throws IOException {  
           screenRecorder.stop();  
      }  
 }  
3.Use it wherever you want to record

No comments:

Post a Comment