I'm using Selendroid in order to test my app. At the beginning of each test I run adb shell screenrecord with the following function:
public static Process startScreenRecord(String fileName) throws IOException{
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", "cd C:\\Users\\user\\Downloads\\adt-bundle-windows-x86_64-20140702\\adt-bundle-windows-x86_64-20140702\\sdk\\platform-tools\\ && adb shell screenrecord /sdcard/" + fileName);
builder.redirectErrorStream(true);
Process p = builder.start();
return p;
}
The recording is starting and everything looks OK. At the end of each test I try to stop the record via the following code:
public static void stopScreenRecord(Process p) throws IOException{
p.destroy();
}
And in the test I use the following structure:
Process p = CmdHelper.startScreenRecord("e1.mp4");
//TestCode
CmdHelper.stopScreenRecord(p);
The problem is that the video recording doesn't stop. How can I stop the call recording at the end of each test?
The adb shell screenrecord --help
documentation says that the two ways to terminate it are to set a time limit or to send it ctrl-C.
Assuming the time limit option doesn't work for you, the question would be how to send ctrl-C or its functional equivalent. If you get an output stream connected to ADB's stdin and keep it open, you might be able to send a ctrl-c down that (or you might end up interrupting ADB and not the remote).
A different option, which seems to work is to use the kill command to send SIGINT (which is what ctrl-C typically does) rather than the SIGTERM signal which kill normally sends. That should make the screenrecord process think you hit ctrl-c.
If you have found the process, id, the following seems to work and leave behind a video file:
adb shell kill -2 [pid number]
Where 2 is the usual number of SIGINT on Linux and thus Android.