UIAutomator启动笔记

配置build.gradle(app目录下):

加入引用库

androidTestCompile'com.android.support.test:runner:0.5'

androidTestCompile'com.android.support.test:rules:0.5'

androidTestCompile'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

//    androidTestCompile 'com.android.support:support-annotations:25.3.1'

新建测试类

@RunWith(AndroidJUnit4.class)

public class HelloWorld {

private UiDevice device;

String PACKAGE_NAME = "com.android.calculator2";

@Before

public void set Up ()  throws Exception {

device= UiDevice.getInstance ( InstrumentationRegistry.getInstrumentation( ) );

//        获取上下文

Context context  =  InstrumentationRegistry.getContext();

//        通过将包名传给包管理器获取启动intent

finalIntent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

//        启动应用

context.startActivity(intent);

//        等待应用启动

device.wait(Until.hasObject(By.pkg(PACKAGE_NAME).depth(0)),10000);

}

@Test

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,089评论 25 709
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,611评论 2 45
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,683评论 0 17
  • 大学里我们有门课叫工程制图,全校基础课。文学,管理,体育,艺术类专业都要学校,平时作业他们就头疼的不行,期末考更是...
    夭特阅读 156评论 0 0
  • 叶落江秋孤舟蔚, 海烟长空一色蓝。 花落人去空落雪, 楚楚凄凄弄停云。 殇酒无味画声峥, 且看离人绾青丝。 ——《...
    清歌浅笑阅读 442评论 0 4