In the previous article in this series, we introduced Monkeyrunner and mentioned that there are some limitations if you write automation scripts based on coordinates (click " read the original text" at the end of the article to open this post). This article will further explain how to write automated scripts based on the ID of the control
Manipulating controls based on the ID of the control
Starting with Android 2.3.3, Monkeyrunner added the Easymonkeydevice and by of the two classes, They are all in the Com.android.monkeyrunner.easy package, and with these two classes, we can manipulate the control based on the ID of the control.
In the previous article in this series, we showed that the absolute coordinates of the control are not the same at different resolutions when the Sogou mobile browser enters the settings page.
At this point if we want to click on one of the controls, such as changing the skin, we need to use the following method:
Where Id/rl_preference_skin is the ID of the control that replaced the skin, so how do you know what the ID of each control is? Another tool for ADT can be hierarchyviewer
To view the ID of a control using Hierarchyviewer
Hierarchyviewer executable file is called Hierarchyviewer.bat, and Monkeyrunner.bat in the same directory, the interface will appear after the run
List in the running activity, click on the Sogou mobile browser settings interface activity--, you can resolve the layout of the entire interface, the process may be slightly slower.
The layout of the application is sometimes very complex, we do not need to find 1.1 points, you can click in the lower right corner of the control we want to view, the control will be selected in the control tree on the left.
In the control tree on the left, the basic information for the control is listed, such as the control ID we need.
Finally, it should be noted that depending on the control's ID to operate the control requires the device to open the Viewserver, most of the devices are not open viewserver, if you can not find the device that has viewserver turned on, use the simulator bar.
Android automated testing using ADT's own tools (iii)