Monkeyrunner recording and playing scripts

Source: Internet
Author: User

# 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 mrfrom com. Android. monkeyrunner. Recorder import monkeyrecorder as recorderdevice = 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 sysfrom 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 cocould be passed to the underlying # command. # lookup table to map command strings to functions that implement that # command. export _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) failed T: Print 'unable to parse options' continue if cmd not in progress _map: Print 'unknown command: '+ cmd continue pai_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 ()
 

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.