想在windows平台运行Monkeyrunner加载图片进行比较

发布于 2024-11-04 20:02:52 字数 338 浏览 1 评论 0原文

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

以上所有都给出错误

回溯(最近一次调用最后一次): 文件“stdin”,第 1 行,位于 AttributeError:类型对象“com.android.monkeyrunner.MonkeyRunner”没有属性 'loadFromFile'

  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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤檠 2024-11-11 20:02:52

要查看 Monkeyrunner 中的内容,请运行此脚本:

#! /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))

您将看到定义的内容和位置。例如,SDK 中的 Monkeyrunner 返回

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 youexpected, build from source。

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.

花开柳相依 2024-11-11 20:02:52

使用Android SDK中最新的Monkeyrunner(目前是r13

在MonkeyRunner模块中使用方法:

MonkeyRunner.loadImageFromFile(imgFullPath)

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

use method in MonkeyRunner module:

MonkeyRunner.loadImageFromFile(imgFullPath)
合久必婚 2024-11-11 20:02:52

我宁愿使用Python的PIL库来完成这项工作。
您必须单独安装 PIL。

将此操作分为两部分。
首先获取当前图像,

使用 PIL 库编写一个 python 脚本,如下所示。

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)

注意:必须安装 python 和 PIL 库才能正常工作。

此函数检查两个图像之间的差异。
current.png 是从设备捕获的,reference.png 是参考图像。
将此代码写入单独的文件中,并从 Monkeyrunner 脚本中调用。

PS 如果您无法破解 Monkeyrunner 代码或者 Monkeyrunner 在后续版本中不提供此功能,请使用它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文