Video Recording during Web Automation

   We know that automation testing entirely relies on the pre-scripted test which runs automatically to compare actual results with the expected results. This helps the tester determine whether an application performs as expected. Automation testing helps to reduce the effort of the regression test suite execution of manual testers.

   Everyone is familiar with Selenium test automation for Web applications and the test automation framework has the capability to generate reports in different formats like HTML, PDF. Also, the frameworks will create a screenshot of the UI when a test fails that depends on the configuration in the Automation Listeners. In this article I would like to share the concept of video recording your automation flows; even if the test case pass or fail or skip, that depends on your configuration in the Automation Listeners.

   Selenium has no built-in capability to record the video of the automation flow. Here I am recording the Selenium automation flow with the help of the Monte Screen Recorder Java library. The Monte media library is used for processing media data. Supported media formats include still images, video, audio, and meta-data. You can record your entire automation flows for future reference to sharing the flow as a demo to your client as well.

   Video recordings of Selenium test case execution can play a major role. Not only would these help in debugging issues more efficiently, but we can also use recorded videos to show test execution activities to the client or other stakeholders. Additionally, these recorded videos can be added to the project management or defect management tool while creating bugs, which helps in understanding the bug clearly.

Pre-requisites:

  • Create a Maven project.
  • Add the following dependencies in the pom.xml file:
    • testng
    • selenium-java
  • Write sample test cases in a test class.
  • Create VideoRecordingUtility class and extends ScreenRecorder class of Monte Recorder library.

   ScreenRecorder class records mouse clicks occurring on other Java Windows running in the same JVM. Mouse clicks occurring in other JVM’s and other processes are not recorded. This ability is useful for performing JVM recordings of an application that is being tested. This recorder uses four threads. Three capture threads for screen, mouse cursor and audio, and one output thread for the movie writer. ScreenRecorder class is a powerful class with many useful methods, here I am using two important methods of ScreenRecorder class which are start and stop. start method helps to record the screen with a defined type (in this example the type is AVI). stop method helps to stop the screen recording. Here I have created two custom methods startVideoRecording and stopVideoRecording. startVideoRecording method has an argument included in the name of the video file. You can create an object of ScreenRecorder and call start and stop methods using that object.

Following are the actual logic implementation inside startVideoRecording method:

public static void startVideoRecording(String testCaseName) {
try {
if (!new File(System.getProperty("user.dir") + "\Reports").exists()) {
(new File(System.getProperty("user.dir") + "\Reports")).mkdir();
}
if (!new File(System.getProperty("user.dir") + "\Reports\Automation_Videos\").exists()) {
new File(new File(System.getProperty("user.dir")), "\Reports\Automation_Videos\").mkdirs();
}
File file = new File(System.getProperty("user.dir") + "\Reports\Automation_Videos\");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = screenSize.width;
int height = screenSize.height;
Rectangle captureSize = new Rectangle(0, 0, width, height);
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
screenRecorder = new ScreenRecording(gc, captureSize,
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, 24, FrameRateKey,
Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),
null, file, testCaseName);
screenRecorder.start();
} catch (Exception e) {
e.printStackTrace();
}
}

Following is the actual logic implementation inside stopVideoRecording method:

public static void stopVideoRecording() {
try {
screenRecorder.stop();
} catch (Exception e) {
e.printStackTrace();
}
}

   The video recording will be stored in Automation_Videos folder under the Reports folder in the project structure. You can use startVideoRecording and stopVideoRecording methods based on your convenience in the automation listener class, if you are using the TestNG framework then you can implement ITestListener interface and use startVideoRecording and stopVideoRecording inside the implemented methods of ITestListener to record the video of entire test suite flow or record pass/fail/skip cases. Try to use the above logic to record your selenium automation flows and enjoy your automation.

make it perfect!

Leave a comment

Create a website or blog at WordPress.com

Up ↑