美文网首页
UIAutomator启动笔记

UIAutomator启动笔记

作者: 不勤奋 | 来源:发表于2017-07-27 16:30 被阅读25次

配置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

相关文章

网友评论

      本文标题:UIAutomator启动笔记

      本文链接:https://www.haomeiwen.com/subject/ownzkxtx.html