• 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()
    
    
    
    
    

  • 相关阅读:
    B-树和B+树
    线程与内核对象的同步-2
    线程与内核对象的同步
    高级线程同步 临界区
    Levenshtein Distance (编辑距离) 算法详解
    平衡二叉树
    静态查找表
    C++中的容器类详解
    How do I list all tables/indices contained in an SQLite database
    SmartGit STUDY 2
  • 原文地址:https://www.cnblogs.com/lgxqf/p/2183755.html
Copyright © 2020-2023  润新知