1. MonkeyRunner Recorder源码(recorder.py):
from com.android.monkeyrunner import MonkeyRunner
from com.android.monkeyrunner.recorder import MonkeyRecorder
device = MonkeyRunner.waitForConnection()
MonkeyRecorder.start(device)
2. 运行MR Recorder:
./sdk/tools$ monkeyrunner recorder.py
3. MR Playback源码(playback.py):
import sys
from com.android.monkeyrunner import MonkeyRunner
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)
}
def process_file(fp, device):
for line in fp:
(cmd, rest) = line.split('|')
try:
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()
4. 运行MR Playback:
./sdk/tools$ monkeyrunner playback.py xxxx(recorder录制的文件名)