Android Automated test Script writing

Source: Internet
Author: User

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

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.