From the name, you can see that this library is an encapsulation of easymonkeydevice.
(This document applies only to wrapeasymonkey 1.0 copyright (c) whoistester.com)
Main purpose of using this library,
1. encapsulate monkeydevice and easymonkeydevice in the library.
2. when performing automated operations, add exception handling to prevent abnormal exit (for example, when a textview is not displayed, capture operation exceptions on the textview to prevent abnormal exit of the test script. if you manually add a sleep statement to the script, but it is difficult to specify the sleep time)
3. Added some convenient functions to reduce the complexity of using monkeydevice and easymonkeydevice.
Note that the wrapeasymonkey library is directly added to the androidviewclient library. The androidviewclient library was developed by Diego Torres Milano to solve the Interaction Problem between monkeyrunner and view. However, it is not easy to use because it is not updated in time. Some of these functions are very useful, so they are not completely separated. It is planned to be separated by the next version. Separate wrapeasymonkey.
How to use it. Download the wrapeasymonkey source code in the Forum.
1. First you need to have the latest Android SDK.
This is just an SDK manager tool. Download and install it, and open it. You can see tools, sdks of different Android versions, such as Android 4.0.3 api15 and API 13, and extras.
You must download at least Android SDK tools and Android SDK platform-tools in tools. If you have downloaded it, we recommend that you upgrade it to the latest version. Because sdks are updated frequently, some files may change, including the folder structure.
2. Download The wrapeasymonkey source code zip package.Decompress the package to a directory. You can decompress the package to the Lib subfolder of the tools folder in the SDK. Of course, it is okay where it is put, because we then set the environment variables so that monkeyrunner can load the scripts to these libraries. But it is not easy for you to manage, so it is recommended to put it in a directory in the SDK.
3. Set environment variables.Setting the environment is not necessary, but if you do not set it, it means that yourProgramAnd library file location cannot be flexible. That is to sayCodeThe address of the database to be loaded must be written. Of course we are not doing this.
1) first, we need to add the android_home environment variable.
2) then the android_view_client_home environment variable. The latter refers to the decompressed path of your wrapeasymonkey source code. For example, after entering c: \ Users \ HP \ downloads \ androidviewclient, we can see that the following directory structure is correct.
3 folders (examples, SRC, tests) and 2 files (. Project,. pydevproject)
3) Add the Tools Folder and platform-Tools Folder In the android SDK to the path of the system environment variable. In this way, we can conveniently call the tools command. Such as ADB, ddms, and hierachyviewer.
4. Write the test script.
The following is an example of a test script (wrapeasymonkey API description and Introduction ). Of course, you can go to the example folder in wrapeasymonkey to find an example.
#! /Usr/bin/ENV monkeyrunner '''Copyright (c) 2012 whoistester.com @ Author: whoistester ''' import reimport sysimport osimport stringimport locale ''' Add the library address to the System Path '''Try: android_view_client_home = OS. environ ['android _ view_client_home '] Does T keyerror: Print> sys. stderr, "% s: Error: android_view_client_home not set in Environment" % _ file _ sys. exit (1) sys. path. append (android_view_client_home + '/src') sys. setdefaultencoding ('utf-8') from Com. dtmilano. android. viewclient import viewclientfrom COM. dtmilano. android. wrapeasymonkey import wrapeasymonkeyfrom COM. android. monkeyrunner import monkeyrunner, monkeydevicefrom COM. android. monkeyrunner. easy import easymonkeydevicefrom COM. android. monkeyrunner. easy import bypackage = 'com. android. contacts 'activity = '. activities. leleactivity 'component = package + "/" + activitydevice = monkeyrunner. waitforconnection (10) # Connecting Device Device. startactivity (Component = component) # Start the Contact application Easydevice = easymonkeydevice (device)# Generating easydevice objects Wrapdevice = wrapeasymonkey (easydevice, device) # Wrapeasymonkey object generated by easydevice and Device Create_contact_button = wrapdevice. getview ('Id/create_contact_button ') # Obtain the view object of the new contact through the wrapeasymonkey object Wrapdevice. touchview (create_contact_button, wrapdevice. down_and_up) # Click the view to call the easymonkey API, Automatically obtains the coordinate value of the view and performs touch. Wrapdevice. Sleep (2) #2 seconds of sleep Wrapdevice. touchdialogbutton (2)# Select the pop-up dialog box. If the parameter is set to 1, select the button on the left. If the parameter is set to 2, select the button on the right. Why not use the touchview function, This is because there is a problem with the latest layout analysis, # The correct coordinate value of alertdialog in the dialog box cannot be obtained. Therefore, touchdialogbutton is controlled by the up and down arrow keys. Wrapdevice. touchviewbyid ('Id/0x3 ', wrapdevice. down_and_up)# Touchviewbyid can directly touch the view ID without obtaining the view object first. Wrapdevice. Type ('test01 ')# Input characters
5. Run the test script.Open the doscommand window or the Linux Shell terminal. Run
"Monkeyrunner script path and name ". Before running the command, make sure that you have correctly installed the mobile phone driver. You can view the driver by using ADB devices.
Reprinted from: http://blog.whoistester.com/2012/07/wrapeasymonkey-howto%E6%96%87%E6%A1%A3/