Basic use of the Android automated test tool Monkeyrunner

Source: Internet
Author: User

A few days ago with colleagues to study the basic use of the next Monkeyrunner, the following with a simple Monkeyrunner examples and share with you (basic operation, the gods can float through ~), The program installs a Android App Package (take an example of a search), and do some simple actions ~ ~ If there are errors welcome to correct



# Modules required to import this program

From Com.android.monkeyrunner import Monkeyrunner, monkeydevice,monkeyimage

From Com.android.monkeyrunner.easy import Easymonkeydevice

From Com.android.monkeyrunner.easy Import by

# connect the current device and return a monkeydevice object

Device =monkeyrunner.waitforconnection ()

Easy_device=easymonkeydevice (device)

# Install the Android package, note that the return value returned by this method is Boolean, so you can determine whether the installation process is normal, the bar right oblique

Device.installpackage (' e:/android/ssj_ad20140808v1.0.1.apk ')

# Run an activity in this app. Note: The app name can be viewed in eclipse

Device.startactivity (component= ' com.sinoglobal.searchingforfood/.activity. Splashactivity ')

# Click Personal Center (click through the control ID)

Easy_device.touch (by.id (' id/iv0 '), monkeydevice.down_and_up)

#进入登录界面后输入用户名

Easy_device.type (by.id (' Id/username '), ' 18311029909 ')

#使密码文本框获得焦点

Easy_device.touch (by.id (' Id/password '), monkeydevice.down_and_up)

#输入密码

Easy_device.type (by.id (' Id/password '), ' 111111 ')

#点击 The Sign In button

Easy_device.touch (by.id (' id/login_btn '), monkeydevice.down_and_up)

#访问我的收藏模块

Easy_device.touch (by.id (' Id/relashicaimingxi '), monkeydevice.down_and_up)

#对当前界面截屏

Result =device.takesnapshot ()

#休眠2秒

Monkeyrunner.sleep (2)

#将截屏图片存入本地

Result.writetofile (' c:\\device.png ', ' png ')


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.