Uiautomatorviewer for App Control

Source: Internet
Author: User

Of

The Android SDK provides the following tools to support our UI Automation testing:

Uiautomatorviewer: A GUI tool for scanning and analyzing UI controls for Android applications.

Uiautomator: A Java library that includes creating tests and executing automated test APIs.

Google Uiautomator docs: http://android.toolib.net/tools/help/uiautomator/index.html

To use these tools, you must install the following versions of Android developer tools:

Android SDK Tools:api version 21 or 21 or later;

Android SDK PLATFORM:API version 16 or more than 16.

Profiling controls

Before you start writing test cases, using Uiautomatorviewer can help you familiarize yourself with your UI components, including views and controls.

You can use it to take a snapshot of the phone screen that is currently connected to your computer, and then you can see the hierarchical relationship of the current page of your phone and the properties of each control. With this information, you can write test cases for specific UI controls.

In.. Open the Uiautomatorviewer.bat in the \sdk\tools\ directory (please connect your phone to your computer before you open it, and start USB debugging on your phone).

Presumably everyone looked at the above dynamic diagram, basically already understood some usage, I further explained:
1. Get Snapshot:
When you want to analyze a page, first stop the phone's page in the page you want to analyze, and then connect the computer with the data cable. Then click on the Second icon button in the top left corner of uiautomatorviewer device screenshot, and then update the snapshot of the current mobile interface here.
2. Page level:
The entire area at the top right is the hierarchical relationship of the current page layout. Understanding this layer should not be a problem if you are familiar with the five major android layouts.

3. Unavailable area:
The second button in the entire area on the top right toggle NAF Nodes, which is represented by a yellow area that appears when pressed, and these controls are not recognized by the Uiautomator tool and cannot be obtained to instances of these controls. Take QQ homepage as an example.

As we can see, when the button is pressed, the yellow area appears in the three tabs below, which represents the controls for the three regions, which is not possible if you want to get their properties through the API provided by Uiautomator, or click on them, because you can't get an instance of these controls.

4. Attribute details:
The entire area at the bottom right is the currently selected page or the property information for the control. This part is more important, when we write code later, we need to get an instance of the control by looking at the ID of the control in the property, or text, and then click to manipulate it.
Take the avatar control in the upper left corner of QQ as an example:

After you click the Avatar control in the upper-left corner, the lower-right area displays details about the control. For example here we can know that its resource-id is com.tencent.mobileqq:id/conversation_head.
You can then use the Uiautomator API method to get an instance of the control.

The method above is to simulate the process of clicking on the control after it has been known, and of course Uiautomator provides a control based on text.

This method of click is better than Monkeyrunner: Monkeyrunner is a coordinate click, when a script is written, a resolution of the phone to execute, the location of the click may be wrong, and uiautomator Click is to find the control first, Then click on the control, so portability is better than Monkeyrunner, and the code is easier to read.

Uiautomatorviewer for App Control

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.