2017-06-16 158 views
0

我想使用UiAutomator来单击系统弹出窗口的按钮。所以我在MainActivity类的一个functin中添加了下面的代码。UiDevice.getInstance失败,出现异常

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

    device.wait(Until.hasObject(By.pkg("com.android.systemui").depth(0)), 2000); 

    try { 
     device.findObject(new UiSelector().textContains("START").className("android.widget.Button")).click(); 
    } 
    catch (UiObjectNotFoundException e){ 
     e.printStackTrace(); 
    } 

但在运行应用程序时,控制台报:

没有仪器注册!在android.support.test.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45)下注册 仪表 必须运行

哪一部分需要修正?我是仪器新手。谢谢。

回答

1

您需要从Android Studio或adb shell am instrument的测试运行中获取测试,而不是从正在运行的应用程序获取。

相关问题