monkey Common API and examples

A, API Introduction

LaunchActivity (pkg_name, cl_name): Start Activity 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.

DispatchPress (keyName):  button. Parameters: keycode. Android Keycode detailed list https://www.cnblogs.com/jane4321/p/11276785.html

DispatchFlip (true / false):  open or close the soft keyboard.

LongPress ():  Press 2 seconds.

PressAndHold (x, y, pressDuration) :  simulate a long press event.

DispatchString (input):  input string.

UserWait (sleepTime):  sleep for some time

DispatchTrackball:  analog transmission trackball events.

DeviceWakeUp ():  wake up the screen.

RunCmd (cmd):  run shell commands.

Second, Screenplay

# Header file, sending a control message monkey parameter
type = RAW Events
COUNT = 10
Speed = 1.0
# monkey the following command
Start Data >>
# Get the name of the package and the Activity
LaunchActivity (com.android.browser, com.android.browser.BrowserActivity)
# let the browser loads the page out, so add delay
UserWait (3000)
# click your browser's address
the Tap (633,1092)
# enter the URL
DispatchString (www.baidu.com)
# enter the enter key
DispatchPress (KEYCODE_ENTER)
# add delay
UserWait (3000)
# enter the home key to return to the desktop
DispatchPress (KEYCODE_HOME)
# kill the process
runCmd (am force-stop com.android.browser)

Precautions:

Script capitalization and spelling to be correct

Simulator developer mode must be turned on, the following two should be open, in order to obtain the coordinates

 

Third, script execution

 

Guess you like

Origin www.cnblogs.com/jane4321/p/11421246.html