"Monkeyrunner" Monkeyrunner script recording and playback

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.