admin 管理员组

文章数量: 887007

Android Studio使用UiAutomator出现连接失败

**

java.lang.IllegalStateException: Cannot call disconnect() while connecting!

**

Android Studio使用UiAutomator编写一个自动化测试脚本,出现:Cannot call disconnect() while connecting!

报错代码:

UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.pressHome();

异常:

FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunnerProcess: com.xgd.scancode, PID: 23664java.lang.IllegalStateException: Cannot call disconnect() while connecting!at android.app.UiAutomation.disconnect(UiAutomation.java:291)at android.app.Instrumentation.finish(Instrumentation.java:249)at androidx.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:381)at androidx.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:463)at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:452)at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2196)

各位大佬,求解决方法

本文标签: Android Studio使用UiAutomator出现连接失败