1.首先创建一个文件夹(如laiwan),命令行切换到laiwa目录下。
2.Android createuitest-project -p . -t android-16。
3.在eclipse中新增java项目(如laiWanTest),将laiwa文件夹下的文件复制粘贴到Eclipse的laiWanTest项目中。
4. 引入sdk\platforms\android-16下的android 及uiautomator jar包;add library-JUnit4。
5.写一段简单的点击"所有应用”试验一下
package com.laiwan.test;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class laiwanTest extends UiAutomatorTestCase {
public void testClickApps(){
UiDevice device =this.getUiDevice();
device.pressHome();
UiObject textView =new UiObject(new UiSelector().description("Apps"));
try {
textView.click();
} catch (UiObjectNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
6.在命令行切换到项目目录(如我的:E:\aworkspace\laiWanTest)运行ant build,在bin目录下生产一个.jar文件。
7.将这个.Jar文件push到手机的/data/local/tmp下。
adb push laiwan.jar/data/local/tmp
8.运行测试。
adb shell uiautomatorruntest laiwan.jar -c com.laiwan.test.laiwanTest
OK 看到模拟器上点击了一下中间的按钮,进入到所有应用。