1. #导入模块;
From Com.android.monkeyrunner import Monkeyrunner, Monkeydevice, Monkeyimage
2. #连接当前设备, and return a Monkeydevice object;
device = Monkeyrunner.waitforconnection ()
If not device:
Print "Please connect a device to start!"
Else
Print "Start"
3. #安装Android包, the return value returned by this method is Boolean, which can be used to determine if the installation process is normal;
Device.installpackage (' myproject/bin/myapplication.apk ')
Device.removepackage (' Com.example.android.notepad ')
Print (' Unload succeeded ')
Device.installpackage (' apidemos.apk ')
Print (' Installation successful ')
4. #启动一个Activity;
Device.startactivity (component= ' com.android.htccontacts/com.android.htccontacts.contactstabactivity ')
5. #;
result = Device.takesnapshot ()
Result.writetofile (' c:\\users\\martin\\desktop\\test.png ', ' png ')
6. #时延 (seconds);
Monkeyrunner.sleep (3)
7. #滑动屏幕;
For I in Range (1,70):
For example:
Device.drag (180,180), (600,600), 0.1,10)
Start, end, duration, step
For I in range (1,100):
Device.drag (180,180), (600,600), 0.1,10)
Monkeyrunner.sleep (1)
8. #触击屏幕;
Device.touch (408,66, "down_and_up")
9. #执行adb shell command;
Device.shell ("Input text Goup01")
Press the HOME button device.press (' Keycode_home ', ' down_and_up ')
Press the back key device.press (' Keycode_back ', ' down_and_up ')
Press the Down navigation key device.press (' Keycode_dpad_down ', ' down_and_up ')
Press the upper navigation key device.press (' keycode_dpad_up ', ' down_and_up ')
Press the OK key device.press (' Keycode_dpad_center ', ' down_and_up ')
The corresponding keys correspond to the following names:
HOME Key: Keycode_home
Back key: Keycode_back
Send key: Keycode_call
End key: Keycode_endcall
Up navigation key: Keycode_dpad_up
Down Navigation key: Keycode_dpad_down
Left navigation: Keycode_dpad_left
Right navigation key: Keycode_dpad_right
OK key: Keycode_dpad_center
Volume up key: Keycode_volume_up
Lower Volume key: Keycode_volume_down
POWER Key: Keycode_power
CAMERA Key: Keycode_camera
MENU Key: Keycode_menu
Monkeyrunner basic elements of Android automated testing (vii)