Use of Monkeyrunner--example practice

Source: Internet
Author: User

Contact Monkeyrunnerfor the first time, do a little exercise, record down in order to facilitate their review later, the need for friends can also refer to. Some places in the article may not understand the wrong, please understand.

Example exercises:

First, use Monkeyrunner to complete the following operations:

1. Install the worktile App

2. start the worktile and intercept the screen

3. Swipe over 5 animated pages on the start page , each time you need to take a screenshot

4. Click the Login button to enter the login page

5. Uninstalling worktile

Prerequisite Preparation:

1.Android Simulator

The 2.Android SDK is already configured in the environment variable .

3. Download worktile from App Store ( download apk website )

======================== officially started ============================

1. Start the android emulator, be sure to start the simulator before you can do the following

2. first verify that the adb 's port number is being used by another program's process

What is--------adb? adb is a tool in the Android SDK that can directly manipulate the andriod emulator or the real Android devices

1) Run cmd, enter command ADB devices

2) If the ADB server is out of date.killing, the adb port is already occupied by another program's process, enter ADB Nodaemon server , view adb port number, typically 5037

Then enter netstat-ano|findstr "5037", you can see the process that occupies the port number 5037 , note the pidof the local occupied ports , kill It in Task Manager

Specific Action link address: http://jingyan.baidu.com/article/d621e8da0dee022865913fce.html

3) If displayed as, correct

4) I am the device that has not shown the connection, namely 192.168.56.101:5555 device This line, the last shutdown restart, the Magic weapon

3. Two ways to create Python code

1) with monkeyrunner.bat Click Run in SDK Tools , you can enter a line of code

2) write the code in Notepad, change the file extension to . PY, and it becomes a . py File

Then run cmd, enter monkeyrunner and Drag the file directly in, as

4. Specific code

import some of the required packages

From Com.android.monkeyrunner import Monkeyrunner

From Com.android.monkeyrunner import Monkeydevice

From Com.android.monkeyrunner.easy import Easymonkeydevice

From Com.android.monkeyrunner.easy Import by

Connection Simulator, if the connection does not respond, may be the port is occupied, return the second step to confirm

Device=monkeyrunner.waitforconnection ()

download Worktile before installation , with the apk address in parentheses

Device.installpackage (' f:/com.worktile_worktile3.4.3_17.apk ')

launch worktile app, in parentheses is the app package name /activity, get the way see the figure below 1

Device.startactivity ("Com.worktile/com.worktile.ui.external.welcomeactivity")

Monkeyrunner.sleep (1)

First start Page

Startpic=device.takesnapshot ()

write Save as Picture address

Startpic.writetofile (' f:/startpic.jpg ', ' jpg ')

Scroll the first sheet of the page

Pic1=device.takesnapshot ()

Pic1.writetofile (' f:/pic1.jpg ', ' jpg ')

Scroll Page Two

Pic2=device.takesnapshot ()

Pic2.writetofile (' f:/pic2.jpg ', ' jpg ')

Scroll Page Three

Pic3=device.takesnapshot ()

Pic3.writetofile (' f:/pic3.jpg ', ' jpg ')

scrolling page Fourth

Pic4=device.takesnapshot ()

Pic4.writetofile (' f:/pic4.jpg ', ' jpg ')

scrolling page Fifth

Pic5=device.takesnapshot ()

Pic5.writetofile (' f:/pic5.jpg ', ' jpg ')

/*

* Click the login button to jump to the login page

* How do I get the ID of the login button ?

*---- Double-click the Hierarchyviewer.bat in tools in the Android SDK (Hierarchy Viewer You can see the page layout,

* get control properties, better view and design user interface ),1, bold part represents the current page, double-click Add

* Rough section,2, specific operation can be Baidu

*/

Figure 1

Figure 2

Easy_device=easymonkeydevice (device)

get the ID of the login button and press down

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

Monkeyrunner.sleep (5)

Uninstall the app, in parentheses is the app 's package name, note that the app 's package name is not apk 's Name Oh

Device.removepackage (' Com.worktile ')

==================== End ====================================

Use of Monkeyrunner--example practice

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.