Tuesday, June 14, 2016

A Video Recorder for your Selenium FW using Monte

Screen recorder for web tests on webdriver by means of java.

1) initialize web driver
     WebDriver driver = new FirefoxDriver();
2) capture video
     initScreen(Path to save video);
3) Stop Video recording
4) Quit web driver
Jars files to add to buildpath : monte-cc.jar, jai_core.jar, jmf.jar

Note: Monte java library is used to implement it http://www.randelshofer.ch/monte/

package common;
import org.monte.media.Format;
import org.monte.media.FormatKeys.*;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import static org.monte.media.FormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;

public class VideoCapture {
    public static ScreenRecorder screenLogger = null;

     * initializes a graphic configurations
    public static void initScreen(String pathToFile) {
// get the graphics configuration of the current screen
GraphicsConfiguration gc = GraphicsEnvironment

// set screen recorder configuration
try {
   screenLogger = new ScreenRecorder(gc, null, new Format(
   MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
   new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,
   24, FrameRateKey, Rational.valueOf(15), QualityKey,
   1.0f, KeyFrameIntervalKey, 15 * 60), new Format(
   MediaTypeKey, MediaType.VIDEO, EncodingKey,
   "black", FrameRateKey, Rational.valueOf(30)), null,
   new File(pathToFile));
} catch (IOException ioe) {
} catch (AWTException awte) {

     * starts the screen recorder
    public static void startVideoCapturing() {
try {
} catch (IOException ioe) {

     * stops the screen recorder
    public static void stopVideoCapturing() {
try {
} catch (Exception e) {