Record and Stream test execution in Appium

Jeeva Tamilselvan
2 min readMay 11, 2020

We all have the Take screenshot on Test failure in our framework. But sometimes the screenshot will not help us. We are like OMG why this test is failing state.

For those, this post will really helpful. We can record the whole test execution as a video with low resolution.

Prerequisite: Please install ffmpeg (brew install FFmpeg)

Start Recording the video

driver.startRecordingScreen();

the above command will simply start the recording with default record options. We can add video quality, fps, time limit, video type, etc.,

Below is the sample code for adding medium video quality for iOS

//iOS
driver.startRecordingScreen(new IOSStartScreenRecordingOptions().withVideoQuality(IOSStartScreenRecordingOptions.VideoQuality.MEDIUM));
//Andoid
driver.startRecordingScreen(new AndroidStartScreenRecordingOptions()....);

Stop Recording the video

String base64output = driver.stopRecordingScreen();

Here if you notice stopRecordingScreen() method is returning a String which is base64String format. we need to decode it to get the video as a file.

base64 String to Video

import java.util.Base64;
import java.nio.file.Paths;
public void tearDown() {
String base64output = driver.stopRecordingScreen();

SimpleDateFormat format = new SimpleDateFormat("dd_MM_yy_hh:mm:ss_aa");
Date date = new Date();
String dateStr = format.format(date);

try {
byte[] data = Base64.getDecoder().decode(base64output);
String destinationPath = "target/ScreenRecord_" + dateStr + ".mp4";
Path path = Paths.get(destinationPath);
Files.write(path, data);

} catch (IOException ex) {
ex.printStackTrace();
}

}

Note: we can use options for stop recording the video as well.

In the above code, we are decoding the base64 string and convert it into a .mp4 file. I’m storing the output screen recording video file in the target folder.

Streaming the test execution — iOS:

The very exciting part is we can see the test execution in the browser window. As soon as we start recording the video, Appium will stream the entire session in localhost:9100

For more info, refer here

--

--