Script recording
1. Connect an Android device or emulator that you have turned on in debug mode, enter ADB devices
2. Run the recording script. In the cmd window, enter Monkeyrunner recorder.py
#recorder. py
__author__ = ' paul ' from Com.android.monkeyrunner import monkeyrunner as Mrfrom com.android.monkeyrunner.recorder import Monkeyrecorder as Recorderdevice = Mr.waitforconnection () recorder.start (device)
3. Start the simulator, you can record the script, the code on the right is your procedure.
4. When the recording is complete, click Export Actions, and then select a folder to save.
Appendix:
Command line execution Monkeyrunner record.py
The prompt error is as follows:
Can ' t open specified script file
Usage:monkeyrunner [Options] Script_file
-S Monkeyserver IP address.
-P monkeyserver TCP Port.
-V Monkeyserver Logging level (all, FINEST, Finer, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)
Workaround:
Full path of Monkeyrunner record.py
Script Playback
1. First we'll look at the recorded script
2. Start the playback script. When you need to be aware, the initial page of the app is consistent with the recording when you play it.
In the cmd window, enter Monkeyrunner playback.py Jiaoben
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, ar G: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 op tions "Continue if cmd not in cmd_map:print" Unknown command: "+ cmd C Ontinue Cmd_map[cmd] (device, rest) def main (): File = sys.argv[1] fp = open (file, "R") Devi CE = monkeyrunner.waitforconnection () process_file (Fp,device) fp.close (); if __name__ = = "__main__": Main ()
3. Watch your phone to run automatically
Appendix:
Command line execution Monkeyrunner playback.py
The prompt error is as follows:
Workaround:
Full path of Monkeyrunner playback.py
"Monkeyrunner" Monkeyrunner script recording and playback