Android Automation Test (1) How to install and uninstall an app

Source: Internet
Author: User

1. Android AAPT
AAPT is an abbreviation for the Android Assert packaging tool that uses AAPT to view the APK information and to list the contents of the APK package


2. Monkey Runner and Chimpchat
The Monkeyrunner tool provides an API for writing programs, control an Android device or emulator from outside of Android OID code.
With the Monkeyrunner, you can write a Python program, the installs an Android application or the test package, runs it,
Sends keystrokes to it, takes screenshots of their user interface, and stores screenshots on the workstation.
The Monkeyrunner tool is primarily designed to test applications and devices at the functional/framework level and for run Ning Unit test Suites,
But is free to use it for other purposes.
The Monkeyrunner tool provides an API to program an Android device or emulator from outside the Android source.
You can use Monkeyrunner to write a Python program to install an Android app and test package, run it, send key event, screenshot, exist locally.
The design of the Monkeyrunner tool originates from a test suite that tests applications and equipment at the functional/framework level, and runs unit tests,
But you can also use it for free for other purposes.


3, use Java to language to invoke the Monkeyrunner API


Import Com.android.chimpchat.adb.adbbackend;import Com.android.chimpchat.core.ichimpdevice;public class MonkeyTest {public    static void Main (string[] args) {        //Sdk/platform-tools have to is in PATH env variable in order to find a DB        Ichimpdevice device = new Adbbackend (). Waitforconnection ();        Print Device Name        System.out.println (Device.getproperty ("Build.model"));        Take a snapshot and save to Out.png        Device.takesnapshot (). WriteToFile ("Out.png", null);        Device.dispose ();    }}

The Library dependencies is:
Chimpchat.jar, Common.jar, Ddmlib.jar, Guava-13.0.1.jar, Sdklib.jar
They can all is found in the Sdk/tools/lib subdirectory of the ADT bundle.


4, Complete installation and unloading package process, so as to complete the first step of automated testing

Package Com.robot.dream.test;import Com.android.chimpchat.adb.adbbackend;import Com.android.chimpchat.core.ichimpdevice;import Com.sinaapp.msdxblog.apkutil.entity.apkinfo;import Com.sinaapp.msdxblog.apkutil.utils.apkutil;public class Monkeytest {public static void main (string[] args) {St        Ring Testapkpath = "d:\\apks_bak\\androidsensorbox.apk";        System.out.println ("Start");        Ichimpdevice device = new Adbbackend (). Waitforconnection ();        System.out.println ("Monkey Test Connected");        Device.installpackage (Testapkpath);        SYSTEM.OUT.PRINTLN ("Install package success");        try {thread.sleep (3000);        } catch (Interruptedexception E1) {//TODO auto-generated catch block E1.printstacktrace ();            try {apkinfo apkinfo = new Apkutil (). Getapkinfo (Testapkpath);            String pkgname = Apkinfo.getpackagename ();            SYSTEM.OUT.PRINTLN ("Package name is" +pkgname); Device.remoVepackage (Pkgname);        SYSTEM.OUT.PRINTLN ("Remove package success");        } catch (Exception e) {e.printstacktrace ();        }//Print Device Name System.out.println (Device.getproperty ("Build.model"));        Take a snapshot and save to Out.png Device.takesnapshot (). WriteToFile ("D:\\out1.png", "PNG");    Device.dispose (); }}


Reference documents:
http://energykey.iteye.com/blog/1856173
Http://developer.android.com/tools/help/monkeyrunner_concepts.html
Http://stackoverflow.com/questions/6686085/how-can-i-make-a-java-app-using-the-monkeyrunner-api?rq=1


Refer to open source projects:
http://code.google.com/p/cfuture09-apkutil/


Code Download:
http://download.csdn.net/detail/vshuang/7964321

Android Automation Test (1) How to install and uninstall an app

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.