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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 耒阳市| 苗栗县| 阿拉善左旗| 响水县| 读书| 秭归县| 永安市| 新野县| 南郑县| 葵青区| 天镇县| 法库县| 兴化市| 睢宁县| 榆社县| 乌拉特前旗| 宣恩县| 岱山县| 青冈县| 建德市| 花莲市| 云龙县| 揭阳市| 安庆市| 英吉沙县| 师宗县| 炎陵县| 饶阳县| 六枝特区| 繁昌县| 大渡口区| 金昌市| 开原市| 鲁山县| 通渭县| 黔南| 白城市| 泰安市| 宁明县| 青川县| 灌阳县|