0

I need to find a solution to test some render scripts. Basically are some applications that display some animations on the screen. If the animation is displayed the test passes if not it fails. I don't have the sources for the apk. Until now using monkeyrunner i used to take 2 screenshots and compare them. If the two pictures where different the tests pass. Now because of a bug in android emulator i cannot take screenshot anymore.

veducm
  • 5,933
  • 2
  • 34
  • 40
X None
  • 9
  • 1
  • Welcome! Usually we try to avoid thank taglines in the questions to keep them tidier, you can read why in here: "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts)". – veducm Jan 27 '14 at 15:23

1 Answers1

0

If you can't take screenshots using MonkeyRunner, I'd suggest trying to take a screenshot on the device using a shell command, pulling the resulting image to the host computer and reading the image to a MonkeyImage.

First, get the device to take a screenshot on it's own:

monkeyDevice.shell("screencap -p /sdcard/screen.png")

Second, pull the screenshot from the device:

from subprocess import call
call(["adb", "pull", "/sdcard/screen.png"])

Third, load the screenshot as a MonkeyImage

image = MonkeyRunner.loadImageFromFile('screen.png')

Now you can compare the images using image.sameAs like normal.

Note that MonkeyRunner.loadImageFromFile was added in SDK version 13.

Carlo B.
  • 1,183
  • 1
  • 11
  • 23
  • I already told you that this is no longer working because of a bug in the andoird, the pictures are always black, so i need a workaroud – X None Jan 28 '14 at 09:41
  • Sorry, I thought only screenshots through MonkeyRunner weren't working from your description. You could potentially write an ActivityInstrumentationTestCase2 class and use getActivity to access the root view. Once you have the root view you can write it to a file in a number of ways (refer to: http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android) and pull the resulting file as outlined above. As you are blackbox testing, you must re-sign the target app with the same key as the instrumentation app using a signing tool: http://www.troido.de/re-sign.jar – Carlo B. Jan 28 '14 at 16:17