Android Automation Test (2) Find objects by ID (Java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.