MonkeyRunner_MonkeyRunnerExamples

#! /usr/bin/env monkeyrunner
    '''
    Created on Apr 1, 2011

    @author: sj
    '''

    import sys

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

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

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

    def screenshot(d):
        MonkeyRunner.sleep(1.0)
        result = d.takeSnapshot()
        MonkeyRunner.sleep(1.0)
        result.writeToFile('/yourPath/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"

        #call(device)
        browse(device)
        debug(device)
        screenshot(device)

        device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')

        MonkeyRunner.sleep(10.0)
    if __name__ == '__main__':
        main()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值