SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Record Appium Test Execution Video For Android App

Appium software test execution video recording Is required when you are executing very large tests and perform multitasking. Recording android device's screen video during software automation testing can helps you to find out when Issue occurred and what are the steps to reproduce Issue. You can Identify why your software test Is failing by looking In to video recording.

Before learning how to record video of android software app automation test execution using appium, You must know how to mirror your android device's screen In PC using androidscreencast as described In my PREVIOUS POST. Android mobile's screen sharing with PC Is required to record video of android app automation test execution. Using androidscreencast, We can share mobile screen with PC and then we can record PC screen's video. Let learn how to Do It.

PREREQUISITE : Android device should be connected wit PC and Android mobile's screen should be shared with PC using androidscreencast.

App To Use and Aim To Achieve
This Is not app specific software test example so you can use any app. We will use here API Demos android software app of android. Here we wants to capture screen of PC so that we can record activities of androidscreencast. We will use ATUTestRecorder to record video of your PC screen. In short, We will use androidscreencast and ATUTestRecorder to record video of android device's screen activities during appium test execution.

Add ATUTestRecorder Jar In Project's Build Path
For recording your PC's screen video, You need to download ATUTestRecorder_2.1.jar file from THIS PAGE and add It In your project's build path. View THIS POST to learn how to add external jar files In project's build path.

Create Test
Create new test file VideoReord.Java In your eclipse's project and use bellow given test script In It.

VideoReord.Java
package Android;

import io.appium.java_client.android.AndroidDriver;

import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import atu.testrecorder.ATUTestRecorder;
import atu.testrecorder.exceptions.ATUTestRecorderException;

public class VideoReord {
 static AndroidDriver driver;
 // Set path of your node.exe file. Set your path.
 // Progra~1 represents Program Files folder.
 String nodePath = "C:/Progra~1/Appium/node.exe";
 // Set path of your appium.js file. Set your path.
 String appiumJSPath = "C:/Progra~1/Appium/node_modules/appium/bin/appium.js";

 ATUTestRecorder recorder;

 @BeforeTest
 public void setUp() throws Exception {
  // Start appium server.
  appiumStart();

  // Get current date and time to provide in recorded video name.
  DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH-mm-ss");
  Date date = new Date();
  // Created object of ATUTestRecorder.
  // Provide path to store videos and file name format.
  recorder = new ATUTestRecorder("D:\\ScriptVideos\\", "TestVideo-" + dateFormat.format(date), false);

  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "ZX1B32FFXF");
  capabilities.setCapability("browserName", "Android");
  capabilities.setCapability("platformVersion", "4.4.2");
  capabilities.setCapability("platformName", "Android");
  capabilities.setCapability("appPackage", "io.appium.android.apis");
  capabilities.setCapability("appActivity", "io.appium.android.apis.ApiDemos");
  driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

  // To start video recording of your PC screen.
  recorder.start();
 }

 @Test
 public void performOrientation() throws InterruptedException {
  // Get and print current screen orientation.
  System.out.println("*--*--*-- Current screen orientation Is : " + driver.getOrientation());
  System.out.println("*--*--*-- Changing screen Orientation to LANDSCAPE.");
  // Changing screen Orientation to LANDSCAPE.
  driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);
  // Get and print screen orientation after changing It.
  System.out.println("*--*--*-- Now screen orientation Is : " + driver.getOrientation());
  Thread.sleep(5000);
  // Scroll till element which contains "Views" text If It Is not visible on screen.
  driver.scrollTo("Views");
  // Click on Views.
  driver.findElement(By.name("Views")).click();
  System.out.println("*--*--*-- Changing screen Orientation to PORTRAIT.");
  // Changing screen Orientation to PORTRAIT.
  driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);
  // Get and print screen orientation after changing It.
  System.out.println("*--*--*-- Now screen orientation Is : " + driver.getOrientation());
  Thread.sleep(5000);
 }

 @AfterTest
 public void End() throws IOException, ATUTestRecorderException {
  driver.quit();
  // Stop appium server when test Is ended.
  appiumStop();
  // Stop video recording.
  recorder.stop();
 }

 // This method Is responsible for starting appium server.
 public void appiumStart() throws IOException, InterruptedException {
  // Created object of apache CommandLine class.
  // It will start command prompt In background.
  CommandLine command = new CommandLine("cmd");
  // Add different arguments In command line which requires to start appium server.
  command.addArgument("/c");
  command.addArgument(nodePath);
  command.addArgument(appiumJSPath);
  // Set Server address.
  command.addArgument("--address");
  command.addArgument("127.0.0.1");
  // Set Port.
  command.addArgument("--port");
  command.addArgument("4723");
  command.addArgument("--no-reset");
  command.addArgument("--log");
  // Set path to store appium server log file.
  command.addArgument("D://appiumLogs.txt");
  // Execute command line arguments to start appium server.
  DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
  DefaultExecutor executor = new DefaultExecutor();
  executor.setExitValue(1);
  executor.execute(command, resultHandler);
  // Wait for 15 minutes so that appium server can start properly before going for test execution.
  // Increase this time If face any error.
  Thread.sleep(15000);
 }

 // This method Is responsible for stopping appium server.
 public static void appiumStop() throws IOException {
  // Add different arguments In command line which requires to stop appium server.
  CommandLine command = new CommandLine("cmd");
  command.addArgument("/c");
  command.addArgument("taskkill");
  command.addArgument("/F");
  command.addArgument("/IM");
  command.addArgument("node.exe");
  // Execute command line arguments to stop appium server.
  DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
  DefaultExecutor executor = new DefaultExecutor();
  executor.setExitValue(1);
  executor.execute(command, resultHandler);
 }
}
Test Decription
  • We have used appiumStart() and appiumStop() methods to start and stop appium. So appium will be started automatically wehn you run your test and you not need to start and stop appium manually.
  • Another thing we have Implemented In script Is video recording of PC screen using ATUTestRecorder. You can change path to store recorded video and video file name as per your requirement.
Running Test

When you run above software test using testng, Immediately keep androidscreencast Interface on top of the screen. Otherwise androidscreencast Interface's screen activities not recorded In video. So when your test started execution, All the android mobile screen's activities will display on your PC screen and ATUTestRecorder will record your PC screen.

This way you can record appium software test execution video for any android app.

2 comments:

  1. Hi Aravind,

    The above article is good. It is recording the PC/Desktop. Is there any other tool to record the Mobile?

    ReplyDelete
  2. Try this below solution
    http://easytestautomation.blogspot.in/2016/06/easy-to-record-screen-in-appium-for.html

    ReplyDelete