Android automated testing (1) how to install and uninstall an application, android Automation

Source: Internet
Author: User

Android automated testing (1) how to install and uninstall an application, android Automation
1. android aapt
Aapt is the abbreviation of android assert packaging tool. With aapt, you can view apk information and list apk Package content.


2. monkey runner and chimpchat
The monkeyrunner tool provides an API for writing programs that controls an Android device or emulator from outside of Android code.
With monkeyrunner, you can write a Python program that installan Android application or test package, runs it,
Sends keystrokes to it, takes screenshots of its 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 running unit test suites,
But you are free to use it for other purposes.
The monkeyrunner tool provides an API for controlling an Android device or simulator by writing programs outside the Android source code.
You can use monkeyrunner to write a Python program to install an Android Application and test package, run it, send key events, screenshots, and store them locally.
The monkeyrunner tool is designed to test applications and devices and run unit tests at the functional/framework level,
But you can also use it for other purposes for free.


3. Use java to call 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 has to be in PATH env variable in order to find adb        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 are:
Chimpchat. jar, common. jar, ddmlib. jar, guava-13.0.1.jar, sdklib. jar
They can all be found in the sdk/tools/lib subdirectory of the ADT bundle.


4. Complete Package installation and uninstallation procedures. This completes 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) {        String 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();    }}


References:
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/


Download Code:
Http://download.csdn.net/detail/vshuang/7964321
Which of the following tools is better for automated testing of android devices?

There are white box tests and black box tests. Now there is a tool called droidpilot for automated testing. I hope it will help you.

How to Control android installation or uninstall applications

After reading a control uninstall, listen to uninstall broadcast and get the package name.
 

Related Article

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.