qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

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


          posted on 2013-07-10 10:40 順其自然EVO 閱讀(1005) 評論(1)  編輯  收藏 所屬分類: android

          評論

          # re: MonkeyRunner_MonkeyRunner 錄制和播放腳本 2013-10-24 10:19 張繼寧

          測試一下,看效果是否滿意  回復  更多評論   

          <2013年7月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宝兴县| 元朗区| 谷城县| 揭东县| 应城市| 洪湖市| 临漳县| 甘洛县| 原平市| 宜春市| 浠水县| 巴里| 永清县| 大埔县| 马鞍山市| 东城区| 沙河市| 安多县| 宜阳县| 三明市| 大名县| 棋牌| 麻江县| 东明县| 新兴县| 瑞安市| 沧州市| 株洲县| 建平县| 广河县| 平远县| 阳曲县| 通江县| 饶阳县| 庆元县| 来宾市| 沙雅县| 山东| 包头市| 宁晋县| 寿光市|