The previous article was written on Android Automation test (1) How to install and uninstall an application (Java), and then explore if you are looking up an object by ID in a normal Java application
1, the class library depends on:
The Library dependencies is:
Chimpchat.jar,common.jar,ddmlib.jar,guava-13.0.1.jar,sdklib.jar,hierchyviewer2lib.jar
They can all is found in the Sdk/tools/lib subdirectory of the ADT bundle.
2. Code:
Package Com.robot.dream.test;import Com.android.chimpchat.adb.adbbackend;import Com.android.chimpchat.adb.linearinterpolator.point;import Com.android.chimpchat.core.ichimpdevice;import Com.android.chimpchat.core.touchpresstype;import Com.android.chimpchat.hierarchyviewer.hierarchyviewer;import Com.android.hierarchyviewerlib.models.viewnode;public class Testrobotdream {public static point Getabsolutecenterofview (Viewnode node) {Point point = Getabsolutepositionofview (node); return new Point (Point.getx () + NODE.WIDTH/2, point.gety () + NODE.HEIGHT/2); public static point Getabsolutepositionofview (Viewnode node) {int x = Node.left; int y = node.top; for (Viewnode p = node.parent; P! = null; p = p.parent) {x + = P.LEFT-P.SCROLLX; Y + = p.top-p.scrolly; } return new Point (x, y); }/** * @param args */public static void main (string[] args) {System.out.println ("start"); IChimpdevice device = new Adbbackend (). Waitforconnection (); SYSTEM.OUT.PRINTLN ("Device OK"); Device.shell ("AM Start com.robot.dream/com.robot.dream.mainactivity"); System.out.println ("Monkey Test Connected"); Hierarchyviewer view = Device.gethierarchyviewer (); Viewnode Viewnode = View.findviewbyid ("Id/center_image"); Point P = Hierarchyviewer.getabsolutecenterofview (Viewnode); Point P = Getabsolutecenterofview (Viewnode); Easymonkeydevice easydevice = new Easymonkeydevice (null); System.out.println ("x:" +p.getx () + "Y:" +p.gety ()); By.id (""); by selector = By.id (""); System.out.println ("Touch 1 OK"); Device.touch (P.getx (), P.gety (), touchpresstype.down_and_up); System.out.println ("Touch 2 OK"); Device.touch (P.getx (), P.gety (), touchpresstype.down_and_up); Easydevice.touch (selector, touchpresstype.down_and_up); Device.dispose (); }}
3. Limitations:
The above automated testing, this approach is implemented using Monkeyrunner corresponding to the Java, Lib.
So it's essentially Java version of Monkey Runner
It can achieve the function, basically monkey Runner can also be achieved, if implemented with Java, less documents, less material, a little more than the loss of the candle.
Explore Java to achieve, the biggest harvest is to these test-related classes of learning.
4, the following will introduce some Android monkeyrunner &android Unit Test &android Code Coverage test
Android Automation Test (2) Find objects by ID (Java)