Heaven Zhuhai Branch Rudder note : Originally this series is to prepare a book, details please see the earlier blog "to seek partners to write the deep understanding of Monkeyrunner" books. But for many reasons, there is no wish. So the draft is shared here, so mistakes are unavoidable. If necessary, please refer to the following, the forwarding of the word also keep the end of each article source and other information.
Notepad window Activity noteslist Introduction
In the previous section, we briefly describe the main functional modules of the test object Notepad, so this section begins with a corresponding elaboration of each module, so that readers who do not actually install and play the application will not affect the reading comprehension of the book.
The first thing we look at is noteslist, the Activity window. After you find the icon for the app on your Android phone, you can click the icon to enter the activity: Notepad
? Figure 2-2-1 noteslist Activity window
The name of the activity window can be obtained using the SDK's own tool hierarchyviewer, which is stored under the Tools directory of your SDK, such as "/users/apple/develop/sdk/" on my machine. Tools/hierarchyviewer ". The user can specify the path to open the tool, and of course, if your environment variable is already set, you can also enter the "hierarchyviewer" command directly to open it. Regardless of whether your work environment is Windows or Linux or Mac, the principle is consistent.
Here we run the Hierarchyviewer tool on the host side when Android has opened noteslist this activity, and the tool lists the following information:
Figure 2-2-2 The incomplete activity name listed in the Hierarchyviewer tool
As you can see, the name of all open activity Windows is listed in the main interface of the tool, where the bold part represents the top activity window, that is, the window currently visible on the target Android machine. The window name is also called the component (component), which consists of two parts: the front part of the slash delimiter "Com.example.android.notepad" is the package name of the Notepad application and is globally unique on the target machine; The next part of the delimiter is the activity's name, which is not shown here, and the full noteslist activity name should be "Com.example.android.notepad.NotesList". We can put the mouse in the name of the control to let hierarchyviewer the activity display complete as follows:
Figure 2-2-3 The full activity name listed in the Hierarchyviewer tool
The main purpose of obtaining the name of the activity in Noteslist is to specify the name to open the Notepad app when writing the Monkeyrunner script.
Noteslist This window is made up of several parts, and viewing the control information for a window can be done through another tool called Uiautomator. The tool is also available under tools in your SDK directory, but it needs to be mentioned that the tool is in Android 4.1 and later, because it comes with Uiautomator, the new UI Automation framework. Let's start by listing a brief description of each control:
- title : noteslist All journals in the interface share the same title, which is a text TextView control
- Journal list : All journals are displayed in this ListView control in the journal list
Let's take a look at the specifics of the header control information captured in Uiautomator:
Figure 2-2-4 Noteslist Title control
From the can see Nostlist title is a textview,uiautomatorviewer in its text content is "Notes"; Resource-id is "Android:id/title", The Monkeyrunner can be used to navigate to the header control, and the Bounds property represents the bounds of the control, defined by the absolute coordinates of the upper-left corner and the absolute coordinates of the lower-right corner (but the system options menu will be different, as we will describe in section 4th). This boundary allows us to determine the effective position of the monkeyrunner when the control is clicked, and the general practice is to take the median of each coordinate boundary, such as the upper-left corner of the upper x-coordinate 6 Plus the lower-right x-coordinate 474 divided by 2 is the x-coordinate of our click 240 , top left 6 coordinates 39 plus the lower right corner y coordinate 74 and divided by 2 is the Y coordinate we clicked on 56, so the final click coordinates should be [240,56].
Of course, the control has a lot of other information, but because the monkeyrunner are not used, so it is not listed.
Let's go ahead and take a look at noteslist. Another control in this window-the contents of the journal Content list ListView:
Figure 2-2-5 noteslist Diary list ListView
Because no journal has been added at this time, all of the controls display an empty list. After we add two diaries, the diary list will look like this:
Figure 2-2-6 Noteslist Diary
The title of the newly added journal is displayed on the left, and the property of the journal displayed on the right is uiautomatorviewer, and you can see that each journal is a textview type of control, and the parent control of those journals is the journal Class tolerance list ListView control.
Heaven Zhuhai Branch Rudder
Public Number: Techgogogo
Weibo: Http://weibo.com/techgogogo
Csdn:http://blog.csdn.net/zhubaitian
2nd Chapter 2 "Monkeyrunner source analysis" Know your test object: Notepad window Activity noteslist Introduction (original)