qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 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 閱讀(1006) 評論(1)  編輯  收藏 所屬分類: android

          評論

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

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

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金华市| 宝丰县| 盐山县| 邓州市| 扶绥县| 大石桥市| 邵武市| 和田县| 大田县| 仪征市| 介休市| 廉江市| 裕民县| 阳原县| 宁阳县| 临桂县| 宁明县| 德昌县| 河源市| 保靖县| 德江县| 石屏县| 赤壁市| 资源县| 南汇区| 扬中市| 五家渠市| 元氏县| 读书| 安新县| 花莲县| 象州县| 乳源| 蒙山县| 循化| 剑河县| 屯留县| 镇平县| 长白| 宽城| 山阳县|