Android automated testing using ADT's own tools (ii)

Source: Internet
Author: User

In the previous article in this series, we introduced the use of monkey, and this article will continue to introduce another automated tool that comes with ADT Monkeyrunner


The relationship between Monkeyrunner and Monkey

In the previous article in this series, we introduced the most common use of monkey, which is to conduct a completely random test (click " read the original text" at the end of the article to open this post for viewing). In this case, monkey will generate some random instructions to execute itself. But if you want to follow a specific sequence of instructions, you need to use Monkeyrunner.

Monkeyrunner is a PC-run program that can send a pre-defined operation instruction to monkey to control monkey for more precise automation.
In fact, Monkeyrunner and monkey This relationship from the name can be seen some clues.

How to use Monkeyrunner
Monkeyrunner sent to Monkey is written in accordance with a specific protocol, here we do not need to care about the specifics of the protocol, only need to write automation scripts in Python, call Monkeyrunner pre-defined functions. It should be noted that although Monkeyrunner uses Python, it does not actually need to install the Python runtime environment, as mentioned earlier, the use of the tools described in this series for Android automated testing does not require the installation of additional tools.

When using Monkeyrunner, you first need to turn on the emulator, or connect the real Android device via USB.
monkeyrunner executable files placed in the SDK's tools directory , is a command-line tool.
You can write scripts in Python anywhere, Then use Monkeyrunner to execute. And these scripts can only be executed through Monkeyrunner, and cannot be executed directly through Python like other py files.

For example at the command line input:
D:\Adt\sdk\tools\ Monkeyrunner D:\sogouqa.py

below this script to adjust the Sogou mobile browser, open the menu and, this script example can be used to check the Sogou mobile browser menu is not displayed properly.



Summary of features supported by Monkeyrunner

  • Physical key operation

  • Screen actions (such as tapping, long-pressing, dragging)

  • Install/Uninstall Apps

  • Multi-device/simulator support

  • Manipulating with controls

  • Execute shell commands (such as the ability to delete files directly)

  • Send Boardcast

  • Recording and playback features


Here is a brief introduction to the recording and playback function, this function does not have a separate program entry, we also need to run a script in Monkeyrunner:



The recording and playback interface will appear when the script finishes executing:


is such a simple interface, click on the left will record a click action, the above row of buttons can add some other actions, such as delay or keyboard action.
Export actions can save the recorded content, but not the Python script file, you also need to write another script to put the recording back and forth, in addition you can also choose to use the coordinates you just recorded to write your own click action.


Limitations of scripting with coordinates

Monkeyrunner default screen operation is based on absolute coordinates, such as the need to further click on the script based on the menu settings, through or script recording tool, you already know the setting menu item coordinates are (72, 684), This allows you to use the Monkeydevice touch method to click the Settings button:

Device.touch (684, "down_and_up")

Unfortunately, we are written in Xiaomi 1 test script, Millet 1S resolution is 480x854, if replaced by other devices, the resolution may change, the location of the Settings button is no longer (72, 684).
Fortunately, in many cases, the location and size of the control is calculated according to the percentage of the screen, for example, regardless of the resolution, Sogou browser settings will appear in the screen 15% wide, 80% high place. This allows us to write automated scripts based on relative coordinates:



In some cases, the position and size of the control does not satisfy the law, such as the settings of the Sogou browser page, millet 1 and millet 42 different devices, a screen can display the content is not the same, you can see that each of the project's relative coordinates between the two devices is difficult to unify.


Finally, if the program is revised and the controls are reordered or laid out, the old automation scripts may be invalidated.
To solve this problem, it is best to write automation scripts in a way other than coordinates. The third article in this series will show you how to write Monkeyrunner Automation scripts using the control's ID.


Android automated testing using ADT's own tools (ii)

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.