uiautomatorviewer for app control acquisition

Preliminary study

The Android SDk provides the following tools to support us in UI automation testing:

uiautomatorviewer: Tool to scan and analyze UI controls of Android applications.

uiautomator: A java library that contains APIs for creating tests and executing automated tests.

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

To use these tools, you must have the following versions of Android Development Tools installed:

Android SDK Tools: API version 21 or above;

Android SDK Platform: API version 16 or above.

Analysis 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 screen of the mobile phone currently connected to your computer, and then you can see the hierarchical relationship of the current page of the mobile phone and the properties of each control. Using this information, you can write test cases for specific UI controls.

Open uiautomatorviewer.bat in the ..\sdk\tools\ directory (please connect the mobile phone to the computer before opening, and enable USB debugging on the mobile phone).

 

 0

After reading the dynamic diagram above, I have basically understood some usages, and I will explain it further: 
1. Take a snapshot:
When you want to analyze a page, first stop the page of the mobile phone on the page you want to analyze, and then use Connect the data cable to the computer.

Then click the second icon button Device Screenshot in the upper left corner of uiautomatorviewer, after clicking, the snapshot of the current mobile phone interface will be updated here.
2. Page level:
The entire area at the top right is the hierarchical relationship of the current page layout. If you are familiar with the five major layouts of Android, understanding this layer should not be a problem.

3. Unavailable area:
The second button Toggle NAF Nodes in the entire area on the upper right, the yellow area that appears after pressing represents that these controls are not recognized by the Uiautomator tool, and instances of these controls cannot be obtained. Take QQ homepage as an example.

0 (1)

We can see that when the button is pressed, a yellow area appears in the three tabs below, which represents the controls of these three areas. If you want to obtain their properties through the API provided by Uiautomator, or perform operations on them Clicking is impossible, because you can't get an instance of these controls.

4. Property details:
The entire area at the bottom right is the property information of the currently selected page or control. This part is more important. When we write code in the future, we need to get the instance of the control by viewing the id or text of the control in the property, and then click to operate it.
Take the avatar control in the upper left corner of QQ as an example:

image

After clicking the avatar control in the upper left corner, the details of the control will be displayed in the lower right area. For example, here we can know that its resource-id is com.baidu.searchbox:id/baidu_searchbox.
Then use the API method of Uiautomator to get the instance of the control.

image

The above method is to simulate the process of inputting text to the control after knowing the id of the control. Of course, Uiautomator also provides to obtain the control according to the text.

Compared with Monkeyrunner, the advantage of this method of clicking is: Monkeyrunner is a coordinate click. When a script is written and executed on a mobile phone with a different resolution, the clicked position may be wrong, and Uiautomator clicks are found first. The control, and then click the control, so the portability is better than Monkeyrunner; in addition, the code is easier to read.

 

http://www.cnblogs.com/lazytest/p/5612709.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326262702&siteId=291194637