A Create a new py suffix file, such as ***.py
Two Import Monkeyrunner Common Packages
From Com.android.monkeyrunner Importmonkeyrunner,monkeydevice,monkeyimage
Three Wait for device to connect
Device=monkeyrunner.waitforconnection ()
Four Monkeyrunner Common operations
1. Pause in the middle of the event, sleep
Monkeyrunner.sleep (2)
Indicates a pause of 2s.
2. Click events, Touch
Device.touch (169,655, ' down_and_up ')
Represents a click (169,255) Coordinate position
3. Sliding events, drag
Device.drag ((335,1092), (335,441), 1,5)
Represents 5 steps from (335,1092) coordinates to the (335,441) coordinates, time consuming 1s.
4. Press
Device.press (' Keycode_power ', ' down_and_up ')
Means click the Power key once
5. Loop for
For I in range (10000):
Represents loops 10,000 times
6. Printing Print
Print I
Mainly used in the For loop to print the number of times
Five Execute script
Monkeyrunner script path such as:
Monkeyrunner c:/***.py
Six View Memory
adb Shell Dumpsys Meminfo | Findstr "Com.android.systemui"
Execute several times before running the script above to record the initial memory
After the execution of the script after the interval of time to see if the memory has been growing, if the growth is not stable, there is a memory leak
Example:
From Com.android.monkeyrunner import Monkeyrunner,monkeydevice,monkeyimage
Device=monkeyrunner.waitforconnection ()
Print 3
Monkeyrunner.sleep (1)
Print 2
Monkeyrunner.sleep (1)
Print 1
Monkeyrunner.sleep (1)
print ' Start ... '
Monkeyrunner.sleep (1)
For I in Range (10000000):
I=i+1
Print I
Device.drag ((355,1240), (355,542), 1,10)
Monkeyrunner.sleep (1.0)
Device.press (' Keycode_power ', ' down_and_up ')
Monkeyrunner.sleep (1.5)
Device.press (' Keycode_power ', ' down_and_up ')
Monkeyrunner.sleep (1.0)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Automated Test scripting