Compiling the android monkey test script

Source: Internet
Author: User

The monkey test tool of Android provides the-F scriptfile parameter, which can be used to specify the test script. However, the script file is not found on the android website, and only the monkeysourcescript source code of monkey is used. java finds a short comment, which provides an example of less than 10 lines:

/** * monkey event queue. It takes a script to produce events *  * sample script format: *      type= raw events *      count= 10 *      speed= 1.0 *      start data >> *      captureDispatchPointer(5109520,5109520,0,230.75429,458.1814,0.20784314, *          0.06666667,0,0.0,0.0,65539,0) *      captureDispatchKey(5113146,5113146,0,20,0,0,0,0) *      captureDispatchFlip(true) *      ... */

With this example, I got a little better done, at least I had a keyword to search, so I quickly found an automated test article using capturedispatchpointer:

Http://qatesttech.wordpress.com/category/android-monkey-script/

(The following is a reference)

"Dispatchpointer"; "dispatchtrackball"; "dispatchkey"; "dispatchflip"; key events of these main functions: see android. view keyevent. javadispatchkey (downtime, // @ Param: the time (in {@ link android. OS. systemclock # uptimemillis}) at which this key code originally went down. millisecond eventtime, // at which this event happened. action, // Action Code: either {@ link # action_down = 0}, {@ link # action_up = 1}, or {@ link # action_multiple = 2 }. code, // the key code. see Appendix 1, for example, keycode_dpad_down (20) keycode_dpad_up (19) Repeat, // a repeat count for down events (> 0 if this is after the initial down) or event count for multiple events. metastate, // flags indicating which meta keys are currently pressed. device, // The device ID that generated the key event. scancode) // raw device scan code of the event. dispatchpointer, dispatchtrackball (downtime, eventtime, action, X, Y, pressure, size, metastate, xprecision, yprecision, device, edgeflags ); @ action the kind of action being completed MED -- one of either {@ link # action_down = 0}, {@ link # action_move = 1}, {@ link # action_up = 2 }, or {@ link # action_cancel = 3 }. @ Param x the X coordinate of this event. @ Param y the Y coordinate of this event. @ Param pressure the current pressure of this event. the pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), however values higher than 1 may be generated depending on the calibration of the input device. @ Param size: A scaled value of the approximate size of the area being pressed touched with the finger. the actual value in pixels corresponding to the finger touch is normalized with a device specific range of values and scaled to a value between 0 and 1. @ Param metastate the State of any meta/modifier keys that were in effect when the event was generated. @ Param xprecision the precision of the X coordinate being reported. @ Param yprecision the precision of the Y coordinate being reported. @ Param DeviceID the ID for the device that this event came from. an ID of zero indicates that the event didn't come from a physical device; other numbers are arbitrary and you shouldn't depend on the values. @ Param edgeflags A bitfield indicating which edges, if any, where touched by this motioneventcapturedispatchflip (true) whether to open the slide, true is to open

The specific usage of each function can only be found in the source code. Another example is found:

Http://qatesttech.wordpress.com/2011/05/05/android-my-monkey-script/

# Start of Scripttype= usercount= 49speed= 1.0start data >>LaunchActivity(com.mpowerlabs.coin.android, com.mpowerlabs.coin.android.LoginActivity)# 3120021258DispatchPress(KEYCODE_3)UserWait(200)DispatchPress(KEYCODE_1)UserWait(200)DispatchPress(KEYCODE_3)UserWait(200)DispatchPress(KEYCODE_5)UserWait(200)DispatchPress(KEYCODE_0)UserWait(200)DispatchPress(KEYCODE_2)UserWait(200)DispatchPress(KEYCODE_1)UserWait(200)DispatchPress(KEYCODE_2)UserWait(200)DispatchPress(KEYCODE_5)UserWait(200)DispatchPress(KEYCODE_8)UserWait(200)# Pin 12345DispatchPress(KEYCODE_DPAD_DOWN)UserWait(250)DispatchPress(KEYCODE_1)UserWait(200)DispatchPress(KEYCODE_2)UserWait(200)DispatchPress(KEYCODE_3)UserWait(200)DispatchPress(KEYCODE_4)UserWait(200)DispatchPress(KEYCODE_5)UserWait(200)# Down and enterDispatchPress(KEYCODE_DPAD_DOWN)UserWait(250)DispatchPress(KEYCODE_ENTER)

Usage:

ADB shell monkey-F <Script File> <Number of script executions>

For example, we put a script to/sdcard/monkey. Script and then run:

ADB shell monkey-F/sdcard/monkey. Script 10, then the specified action in this script will be executed 10 times.

List of compiled script functions:

DispatchPointer(long downTime,  long eventTime, int action,    float x, float y, float pressure, float size, int metaState,    float xPrecision, float yPrecision, int device, int edgeFlags)DispatchTrackball(long downTime,  long eventTime, int action,    float x, float y, float pressure, float size, int metaState,    float xPrecision, float yPrecision, int device, int edgeFlags)DispatchKey(long downTime, long eventTime, int action, int code,    int repeat, int metaState, int device, int scancode)DispatchFlip(boolean keyboardOpen)DispatchPress(int keyCode)LaunchActivity(String pkg_name, String cl_name)UserWait(long sleeptime)LongPress()

For the key value list, see http://developer.android.com/reference/android/view/keyevent.html.

Related Article

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.