LoginSignup
5
5

More than 5 years have passed since last update.

monkeyrunnerで画像比較

Posted at

練習を兼ねて投稿。
Androidのmonkeyrunnerで画像比較するサンプル。

qiita.py

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

# Installs the Android package. Notice that this method returns a boolean, so you can test
# to see if the installation worked.
#device.installPackage('myproject/bin/MyApplication.apk')

# sets a variable with the package's internal name
#package = 'com.example.android.myapplication'

# sets a variable with the name of an Activity in the package
#activity = 'com.example.android.myapplication.MainActivity'

# sets the name of the component to start
#runComponent = package + '/' + activity

# Runs the component
#device.startActivity(component=runComponent)

# Presses the Menu button
#device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)

ref = MonkeyRunner.loadImageFromFile('shot1.png', 'png')


while 1:
    # Takes a screenshot
    result = device.takeSnapshot()

    # Writes the screenshot to a file
    #result.writeToFile('shot2.png','png')

    if result.sameAs(ref, 0.99):
        print "OK"
        break
    else:
        print "NG"
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5