Ravi
Ravi

Reputation: 41

Want to run Monkeyrunner to load image for comparison in windows platform

  1. checking=MonkeyRunner.loadImageFromFile(chk)
  2. checking=MonkeyRunner.loadFromFile(chk)
  3. checking=MonkeyImage.loadFromFile(chk)

all the above give error

Traceback (most recent call last): File "stdin", line 1, in AttributeError: type object 'com.android.monkeyrunner.MonkeyRunner' has no attri bute 'loadFromFile'

Upvotes: 1

Views: 4257

Answers (3)

Xiao
Xiao

Reputation: 12695

use the latest Monkeyrunner in Android SDK (at present is r13)

use method in MonkeyRunner module:

MonkeyRunner.loadImageFromFile(imgFullPath)

Upvotes: 2

Vinayak Kolagi
Vinayak Kolagi

Reputation: 1881

I would rather use PIL library of python to do this job.
You have to install PIL seperately.

Split this operation in two parts. First take the current image

Write a python script using PIL library as given below.

from PIL import Image
from PIL import ImageChops

def equal(im1, im2):
    return ImageChops.difference(im1, im2).getbbox() is None

im1 = Image.open("current.png")
im2 = Image.open("reference.jpg")
equal(im1, im2)

Note: python and PIL library has to installed for this to work.

This function checks the difference between two images.
current.png is captured from device and reference.png is the reference image.
Write this code in seperate file and call from monkeyrunner script.

P.S. Use it if you can't hack the monkeyrunner code or monkeyrunner doesn't provide this functionality in later releases.

Upvotes: 0

Diego Torres Milano
Diego Torres Milano

Reputation: 69228

To see what's in your monkeyrunner, run this script:

#! /opt/android-sdk/tools/monkeyrunner

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

for m in [MonkeyRunner, MonkeyDevice, MonkeyImage]:
    print "%s:\n   %s\n" % (m.__name__, dir(m))

You will see what's defined and where. For example, the monkeyrunner in the SDK returns

MonkeyRunner:
   ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'alert', 'choice', 'help', 'input', 'sleep', 'waitForConnection']

MonkeyDevice:
   ['DOWN', 'DOWN_AND_UP', 'UP', '__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'broadcastIntent', 'drag', 'getProperty', 'getSystemProperty', 'installPackage', 'instrument', 'press', 'reboot', 'removePackage', 'shell', 'startActivity', 'takeSnapshot', 'touch', 'type', 'wake']

MonkeyImage:
   ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'convertToBytes', 'getRawPixel', 'getRawPixelInt', 'getSubImage', 'sameAs', 'writeToFile']

If it's not as you expected, build from source.

Upvotes: 4

Related Questions