Friday, May 8, 2015

monkeyrunner

2011년 탐구하던 주제... 
샘플 코드이다. 

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

def lockDevice(device):
    return device.press("POWER", MonkeyDevice.DOWN_AND_UP)

def unlockDevice(device):
    device.wake()
    device.drag((50, 450), (250, 450))

def browse(d):
    d.broadcastIntent("http://www.google.com/", "ACTION_MAIN")
    d.startActivity(component="com.android.browser/.BrowserActivity")

def debug(device):
    print" package:%s" % str(device.getProperty('am.current.package'))
    print" action:%s" % str(device.getProperty('am.current.action'))
    print" comp.class:%s" % str(device.getProperty('am.current.comp.class'))
    print" comp.package:%s" % str(device.getProperty('am.current.comp.package'))
    print str(device.getProperty('display.width')), str(device.getProperty('display.height'))

def screenshot(d):
    MonkeyRunner.sleep(1.0)
    result = d.takeSnapshot()
    MonkeyRunner.sleep(1.0)
    result.writeToFile('screenCapture/device.png', 'png') 

def call(d):

    d.startActivity(component="com.android.contacts/.TwelveKeyDialer")
    print "Start Activity"
    MonkeyRunner.sleep(1.0)
    d.type("+XXXXXXXX")    # Call number.
    print "Call"
    d.touch(190, 800, 'DOWN_AND_UP');
    # not working device.press('KEYCODE_CALL', 'DOWN_AND_UP')
    print "Wait 10 sec"
    MonkeyRunner.sleep(10.0)
    # HangUp Call
    device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')
    print "Hang Up"
    #x1 = 215
    #x2 = 230
    #y = 700
    #start = (x1,y)
    #end = (x2, y)
    #steps = 2
    #pause = 0.2
    #device.drag(start, end, pause, steps)

    d.startActivity(component="com.android.phone/.InCallScreen")
    #device.touch(230, 700, "DOWN");
    MonkeyRunner.sleep(1.0)
    #device.touch(230, 700, "UP");

    d.touch(230, 700, 'DOWN_AND_UP');
    #device.touch(270, 650, 'DOWN_AND_UP');


def main():
    print "Start"

    # Connect to the current device returning the MonkeyDevice object
    device = MonkeyRunner.waitForConnection()

    #MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")

    if not device:
        print "Couldn't get connection"
        sys.exit()
    print "Found device"



if __name__ == '__main__':
    main()

No comments: