Be careful when using monkeyrunner

Source: Internet
Author: User

The monkeyrunner (not the Monkey) provided by the android SDK is powerful for functional testing, and it is easy to use. You can follow the instructions in this document.

During use, it is found that the simulation of gesture is not so easy to use, that is, the drag () method. At home, there is no problem. You can see the screen drag action, but it does not respond in your own application. Logcat detects that the ongesturelistener. onlongpress () interface is actually triggered, so you need to disable it and call setislongpressenabled (false. This is also true when double-clicking is simulated. It is found that monkeyrunner's press () is also intercepted by onlongpress. However, in actual use of your own applications, this is not the case, that is, when setislongpressenabled (true), drag and double-click are all correct, and onlongpress () is not triggered ().

I have not read the monkeyrunner source code. This is just a solution from log for reference. If you have other solutions, we hope to discuss them.

In addition, monkeyrunner tries its best to avoid the dependence on coordinates, especially for automatic tests on screens that require multiple SDK versions and different sizes (I wonder if it can dynamically pass getpropery (display. width/height) to adjust, this has not been studied ). In most cases, it can be avoided (as long as this operation can be completed through the simulator button ):

1) For example, if you click different buttons in the dialog box, you can simulate them by left _ key and enter first.

2) For example, you can use left_key and down_key to locate the menu based on The number and position of the menu to be selected.

Of course, there is no good way to click those components without focus.

You can use the recorder class to record test cases for a single device.

----------------

Update. Just now I checked the latest monkeyrunner code and started to use the ID to interact with the application, instead of using the coordinates. This makes it easier to use and paste the README in a section.

com.android.monkeyrunner.easy contains classes intended to make it easierto interact with applications using the MonkeyRunner framework. Instead ofreferencing a button or input box by x,y coordinate, they can be referencedby identifier, as in the following Python example:##############################################################################from com.android.monkeyrunner import MonkeyRunner, MonkeyDevicefrom com.android.monkeyrunner.easy import EasyMonkeyDevicefrom com.android.monkeyrunner.easy import By# Connect to the current device.device = MonkeyRunner.waitForConnection()# Use the EasyMonkey API, all methods on device are available in easy_device.easy_device = EasyMonkeyDevice(device)if not easy_device.visible(By.id('id/all_apps_button')):    raise Error('Could not find the "all apps" button')print "Location of element:", easy_device.locate(By.id('id/all_apps_button'))easy_device.touch(By.id('id/all_apps_button'), 'DOWN_AND_UP')##############################################################################WARNING: This API is under development and may change without notice.

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.