1.在 Eclipse 新建工程
2.导入 Android sdk 目录下platform 下 android-24中的 android.jar 包和 uiautomator.jar 包
3.在工程中继承 UiAutomatorTestCase 类
package com.text;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class Test extends UiAutomatorTestCase {
public void testDemo(){
//按 home 键
UiDevice.getInstance().pressHome();
}
}
4.编译与运行代码
可随意起用户名字
项目路径
android create uitest-project -n <jars > -t 1 -p <workspace path>
5.进入项目,Refresh
6.进入工作项目中的 build.xml 文件,将第二行的 help 修改为 build (修改 build.xml 文件)
7.ant -buildfile<build.xml文件路径>(开始编译)
8.adb push <path_to_output_jar>/data/local/tmp(push 文件)
9.adb shell uiautomator runtest <jars> -c <包名>.<类名>[#test name]