我想使用UiAutomator点击一个系统弹出窗口的按钮。所以我在我的MainActivity类的一个函数中添加了下面的代码。
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)的注册工具下运行。
哪一部分需要修理?我对仪器很陌生。谢谢。
发布于 2017-06-16 17:43:48
您需要从从Android或adb shell am instrument运行的测试中获得该工具,而不是从运行中的应用程序中获得。
https://stackoverflow.com/questions/44582809
复制相似问题