Monkeyrunner basic elements of Android automated testing (vii)

Source: Internet
Author: User

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)

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.