The ScreenRecord command is able to record the display of devices running Android 4.4 (API level 19) and higher. The tool is recording the app interaction to an MPEG-4 file, which can be downloaded from the device using the command 

. This video can then be used as part of your bug report as well.

The following sample will start a recording session of the connected device.

To stop the screen recording press 

, otherwise the recording will stop automatically after three minutes. However, you can also define a time limit with the paramter 

.

The tool is recording the video in the native display resolution and orientation by default. However, there are some limitations of the screenrecord command that you should know when using it:

To begin recording your device screen, run the 

 command to record the video. Then, run the 

 command to download the video from the device to the host computer. Here’s an example recording session:

The 

 utility can record at any supported resolution and bit rate you request, while retaining the aspect ratio of the device display. The utility records at the native display resolution and orientation by default, with a maximum length of three minutes.

 

 options

Options Description
Displays command syntax and options
Sets the video size:  . The default value is the device’s native display resolution (if supported), 1280×720 if not. For best results, use a size supported by your device’s Advanced Video Coding (AVC) encoder.
Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 6Mbps:

Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
Rotates the output 90 degrees. This feature is experimental.
Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running.

 

Refer the below script to record the Android device, It will be created as video file and move it in to our project directory, and finally it remove the recorded file in android device.

ScreenRecorder.java

 

Start Recording:

The Recorded file will be created by given name.

Stop Recording:

We have to give three Parameters to stop the Recording, The first Parameter is a file name which we created at that time of start recording, Second parameter is a directory path to where we want move the file.

 

And third Parameter set it as ‘true’ to remove the recorded file in Mobile device.

 

Sample Test case for Screen Record.

ViewPageTC_ScreenRecord.java

 

Very often we would like to record our interaction with the screen to demo our feature. We can do this easily with ADB (Android Debug Bridge).

Note: To do that, the pre-requisite is to first connect our device to our computer, and allow it to be debuggable. Also we need to have Android Studio installed.

Reference:

http://adbshell.com/commands/adb-shell-screenrecord