Page 1 of 1

Taking a full screenshot of the android device

Posted: Mon Aug 24, 2015 2:05 pm
by sandamal
Hi,

Im automating an android application.
Is there any option in record modules to make a complete screen shot of the Android screen in to the report.

what I found is it is only possible to specify the element and take the screen shot of that. ( when i did not specify the element it took the screen of the Laptop screen - Im connecting the android device via USB to the laptop and running tests on android device )
Using ranorex 5.2.2.21xxx

please advice :roll:

Re: Taking a full screenshot of the android device

Posted: Mon Aug 24, 2015 4:44 pm
by lucian.teodorescu
Hi sandamal,

Whenever I need 'the whole picture' I take a screenshot of the application itself (since you test the app, and Ranorex can handle only instrumented apps).
The only time when taking the screenshot is not possible is when the app is closed. Also, any screenshot of the app doesn't capture any device system pop-up.

Maybe you could give us some details in which situation you cannot use screenshot of the entire app.
Meanwhile, here is a "first try" and resources consuming method, with the following steps:
- use adb command to take screenshot
- use adb command to save screenshot to your PC
- log the screenshot to your report
- clean (delete file from device and PC)

Copy-Paste this code into user code module
*** add 'using System.IO;' reference

Code: Select all

string pathToAdb = "C:\\xxxxxxxx\\Android SDK\\sdk\\platform-tools\\adb.exe";   //your path to adb.exe goes here

//take screenshot
Process adbTakeScreenshot = new Process();
adbTakeScreenshot.StartInfo.FileName  = pathToAdb;
adbTakeScreenshot.StartInfo.Arguments = string.Format(" shell screencap /sdcard/Download/myScreenshot.png");
adbTakeScreenshot.Start();
adbTakeScreenshot.WaitForExit();

//save screenshot to PC
Process adbGetScreenshot = new Process();
adbGetScreenshot.StartInfo.FileName  = pathToAdb;
adbGetScreenshot.StartInfo.Arguments = string.Format(" pull /sdcard/Download/myScreenshot.png \"C:\\Temp\\screen.bmp\"");
adbGetScreenshot.Start();
adbGetScreenshot.WaitForExit();
			
//log your screenshot	into report	Report.LogData(ReportLevel.Info,"Info",Ranorex.Imaging.Load(@"C:\\Temp\\screen.bmp"));
			
//remove file from USB device
Process adbRemoveFile = new Process();
adbRemoveFile.StartInfo.FileName  = pathToAdb;
adbRemoveFile.StartInfo.Arguments = string.Format(" shell rm /sdcard/Download/myScreenshot.png");
adbRemoveFile.Start();
adbRemoveFile.WaitForExit();
		
//remove file from your PC
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
File.Delete(@"C:\\Temp\\screen.bmp");
Let us know what solution worked for you, even if is one listed here or not.