zoukankan      html  css  js  c++  java
  • MonkeyRunner 录制和播放脚本

    #Usage: monkeyrunner recorder.py

    #recorder.py  http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py

    from com.android.monkeyrunner import MonkeyRunner as mr
    from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
    
    device = mr.waitForConnection()
    recorder.start(device)
    #END recorder.py
    #Press ExportAction to save recorded scrip to a file
    #Example of result:
    #PRESS|{'name':'MENU','type':'downAndUp',}
    #TOUCH|{'x':190,'y':195,'type':'downAndUp',}
    #TYPE|{'message':'',}
    
    ============================================================================================
    #Usage: monkeyrunner playback.py "myscript"
    #playback.py   http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
    import sys
    from com.android.monkeyrunner import MonkeyRunner
    
    # The format of the file we are parsing is very carfeully constructed.
    # Each line corresponds to a single command.  The line is split into 2
    # parts with a | character.  Text to the left of the pipe denotes
    # which command to run.  The text to the right of the pipe is a python
    # dictionary (it can be evaled into existence) that specifies the
    # arguments for the command.  In most cases, this directly maps to the
    # keyword argument dictionary that could be passed to the underlying
    # command. 
    
    # Lookup table to map command strings to functions that implement that
    # command.
    CMD_MAP = {
        'TOUCH': lambda dev, arg: dev.touch(**arg),
        'DRAG': lambda dev, arg: dev.drag(**arg),
        'PRESS': lambda dev, arg: dev.press(**arg),
        'TYPE': lambda dev, arg: dev.type(**arg),
        'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
        }
    
    # Process a single file for the specified device.
    def process_file(fp, device):
        for line in fp:
            (cmd, rest) = line.split('|')
            try:
                # Parse the pydict
                rest = eval(rest)
            except:
                print 'unable to parse options'
                continue
    
            if cmd not in CMD_MAP:
                print 'unknown command: ' + cmd
                continue
    
            CMD_MAP[cmd](device, rest)
    
    
    def main():
        file = sys.argv[1]
        fp = open(file, 'r')
    
        device = MonkeyRunner.waitForConnection()
        
        process_file(fp, device)
        fp.close();
        
    
    if __name__ == '__main__':
        main()
    
    
    
    
    

  • 相关阅读:
    centos7 安装mysql
    Nginx安装及配置详解
    nginx安装
    JSON Web Token
    优先队列
    小程序遮罩层禁止页面滚动(遮罩层内部可以滚动)
    H5中接入微信支付
    如何使用less预编译
    在methods中使用filter
    根据当前时间获取上一个月的时间
  • 原文地址:https://www.cnblogs.com/lgxqf/p/2183755.html
Copyright © 2011-2022 走看看