monkey custom scripts practice
An obtaining position coordinates of elements
Two, Monkey scripting API Introduction
Monkey conventional test execution flow of random events, but if you just want Monkey test a particular scene this time you need to use a custom script, Monkey support the implementation of user-defined test scripts, users need only follow the script of the Monkey specification writing good scripts, stored on your phone, you can start the script by calling Monkey -f parameter.
LaunchActivity (pkg_name, cl_name): Activity start the application. Parameters: the package name and start the Activity.
Tap (x, y, tapDuration) : Simulation of a finger click event. Parameters: x, y coordinates for the control, tapDuration for the duration of clicks, this parameter can be omitted.
UserWait (sleepTime): sleep period
DispatchPress (keyName): button. Parameters: keycode. RotateScreen (rotationDegree, persist): rotate the screen. Parameters: rotationDegree rotation angle, eg 1 representative of 90 degrees; the persist indicating whether fixed after the rotation, the rotated recovery represents 0, 0 indicates the non-fixed.
DispatchString (input): input string.
DispatchFlip (true / false): open or close the soft keyboard.
PressAndHold (x, y, pressDuration) : Press event simulation.
Drag (xStart, yStart, xEnd, yEnd, stepCount): used to simulate a drag operation.
PinchZoom (x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End, stepCount): analog zoom gesture.
LongPress (): Press 2 seconds.
DeviceWakeUp (): wake up the screen.
PowerLog (power_log_type, test_case_status): Analog battery power information.
WriteLog (): the battery information into the sd card.
RunCmd (cmd): run shell commands.
DispatchPointer (downtime, eventTime, action, x, yxpressure, size, metastate, xPrecision, yPrecision, device, edgeFlags): the designated location, sending a single gesture.
DispatchPointer (downtime, eventTime, action, x, yxpressure, size, metastate, xPrecision, yPrecision, device, edgeFilags): sending a PUSH message.
LaunchInstrumentation (test_name, runner_name): Run a test instrumentation.
DispatchTrackball: analog transmission trackball events.
ProfileWait: Wait 5 seconds.
StartCaptureFramerate (): Gets the frame rate.
EndCaptureFramerate (input): Gets the end frame rate.
Third, script writing
A, the script format
Monkey script mainly consists of two parts, one is the header file information, the monkey is a specific part of the command.
= RAW Events of the type
COUNT = 1
Speed = 1.0
// The following command monkey
Start the Data >>
specific monkey script content
# Header information
of the type = RAW Events
COUNT = 1
Speed = 1.0
#启动测试
start data >>
LaunchActivity(com.tal.kaoyan,com.tal.kaoyan.ui.activity.SplashActivity)
UserWait(2000)
Tap (624,900,1000) # Click to cancel the upgrade
UserWait (2000)
Tap (806,64,1000) # Click to skip
UserWait (2000)
Tap (217,378,1000) # click on the user name input box
DispatchString (zxw1234)
UserWait (2000)
Tap (197,461,1000) # Click password input box
DispatchString (zxw123456)
UserWait (2000)
Tap (343,637,1000) # click the login button
Fourth, the execution of the script
After the completion of scripting, spread on mobile devices, and then executed.
adb push D:\mon\mon.txt /sdcard
adb shell mokey -f /sdcard/mon.txt -v 1