Monday, 22 September 2014

Recording a screen of what you are testing using selenium...

The screenrecorder used to track the where is the issue and which button/ui element is not working and also
 its usefull for showing the proof of bugs to dev..

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 java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.monte.media.Format;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login {
@Test
public static void main(String[] args) throws IOException, AWTException {
ScreenRecorder screenRecorder;

GraphicsConfiguration gconfig = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();

screenRecorder = new ScreenRecorder(gconfig, 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);

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
screenRecorder.start();
driver.manage().window().maximize();
driver.get("enter your url");
//do some opertion here.
screenRecorder.stop();
//driver.close();
}

}

the recorded vidio is saved in your C:\Users\ngowda\Videos//screenrecorder.

No comments:

Post a Comment