testing-samples icon indicating copy to clipboard operation
testing-samples copied to clipboard

UiAutomator findObject is throwing IllegalStateException: UiAutomation not connected!

Open sravanmedarapu opened this issue 9 years ago • 26 comments
trafficstars

Getting below Exception for every consecutive execution

java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971)
at android.app.UiAutomation.waitForIdle(UiAutomation.java:577)
at android.support.test.uiautomator.UiAutomatorBridge.waitForIdle(UiAutomatorBridge.java:112)
at android.support.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:639)
at android.support.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:629)
at android.support.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1074)
at android.support.test.uiautomator.UiDevice.findObject(UiDevice.java:164)

observed throwing above exception immediately after executing below statement in logcat

W WindowManager: Attempted to remove non-existing token: android.os.Binder@2728fc2

Tested on API Level: 19, 21, 23 emulators, issue also replicating in real device Uiautomator Version: com.android.support.test.uiautomator:uiautomator-v18:2.1.2

Please let me know if you need any other information.

sravanmedarapu avatar Apr 19 '16 06:04 sravanmedarapu

Why is there no way for UiAutomation to automatically reconnect on disconnect?

bootstraponline avatar Apr 19 '16 14:04 bootstraponline

I am getting the same error. Is there a way to work around this?

tpetsas avatar Aug 10 '16 17:08 tpetsas

Possible workaround is restarting adb before the test run with adb kill-server; adb start-server. That worked for me on another project.

kevin-brotcke avatar Sep 01 '16 07:09 kevin-brotcke

@kevin-brotcke thanks for the advice. The thing is that this exception is raised during the test and AFAIK there is no way to catch it and issue those commands. Have you experienced the same behavior?

tpetsas avatar Sep 14 '16 15:09 tpetsas

I'm re-running the tests when we hit this failure. Although, my workaround above only decreases the frequency, I still see it occasionally.

kevin-brotcke avatar Oct 13 '16 23:10 kevin-brotcke

I am also having the same problem java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971)

Getting this occasionally while test case execution, so count not be possible to kill and start adb server in the middle and there is no way to catch it as well. please help you somebody have solution for this.

Thanks.

Arvind0203 avatar Mar 20 '17 05:03 Arvind0203

Consistently happening for me. Device restart resolves sometimes but once it appears, consistency is 10/10 post that:

04-23 17:22:13.108 12796-12812/? E/AndroidRuntime: FATAL EXCEPTION: Thread-2 Process: com.example.rakeshs.uiautomator, PID: 12796 java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034) at android.app.UiAutomation.executeShellCommand(UiAutomation.java:982) at com.example.rakeshs.uiautomator.util.Utils.runCommand(Utils.java:387) at com.example.rakeshs.uiautomator.util.Utils.profileCPUInfo(Utils.java:120) at com.example.rakeshs.uiautomator.util.Utils$1.run(Utils.java:99)

For me it is always happening at executeShellCommand step.

r-sharma avatar Apr 21 '17 11:04 r-sharma

Looks to be some sync issue which got resolved for me on adding some sleep before executeShellCommand():

mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); assertThat(mDevice, notNullValue()); mDevice.pressHome(); InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand("pm clear <app_package_name>"); openApp(getConfigProperty(<app_package_name>)); .... .... Thread.sleep(5000); .... p = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(cmd);

r-sharma avatar Apr 21 '17 17:04 r-sharma

Hi @sravanmedarapu

i have also same issue , Error log ...

Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:914) at android.app.UiAutomation.disconnect(UiAutomation.java:236) at android.app.Instrumentation.finish(Instrumentation.java:220) at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351) at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1933)

GauravCreed avatar Dec 18 '17 06:12 GauravCreed

I am also getting same issue, when running robo tests on Firebase Cloud test infrastructure.

Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected!
       at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034)
       at android.app.UiAutomation.disconnect(UiAutomation.java:275)
       at android.app.Instrumentation.finish(Instrumentation.java:210)
       at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351)
       at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405)
       at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394)
       at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)

snijsure avatar Dec 19 '17 22:12 snijsure

Also getting the exact same report, when submitting an app for Alpha Testing on the Play Store

manuelrego27 avatar Dec 20 '17 16:12 manuelrego27

Same issue when submitting for Open Beta on the Play Store:

Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971) at android.app.UiAutomation.disconnect(UiAutomation.java:237) at android.app.Instrumentation.finish(Instrumentation.java:222) at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351) at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1970)

martin-price87 avatar Feb 15 '18 23:02 martin-price87

Same issue when submitting to play store:

java.lang.IllegalStateException: UiAutomation not connected!
        at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034)
        at android.app.UiAutomation.disconnect(UiAutomation.java:275)
        at android.app.Instrumentation.finish(Instrumentation.java:210)
        at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351)
        at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405)
        at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)

jsonpoindexter avatar Mar 06 '18 20:03 jsonpoindexter

I mean it is 06.04.2018 (!). What about to solve the Issue?

recodyx avatar Apr 06 '18 15:04 recodyx

Same issue from my side any ideas how to fix this ? screen shot 2018-06-06 at 12 54 33 pm

alejouribesanchez avatar Jun 06 '18 17:06 alejouribesanchez

Even i faced the same issue ...!

it fixed by doing adb kill-server , adb start-server .

arunsai94 avatar Jun 26 '18 12:06 arunsai94

@arunsai94 not works! also adb is a command for debugging and I am talking about production issue.

alejouribesanchez avatar Jun 26 '18 15:06 alejouribesanchez

Same thing. Been happening ever since I started Android automation. Occurs every hour or so. Makes testing very difficult...please fix!

--------- beginning of crash 07-03 10:36:10.755 9455 9455 E AndroidRuntime: FATAL EXCEPTION: main 07-03 10:36:10.755 9455 9455 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 9455 07-03 10:36:10.755 9455 9455 E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: src.length=7 srcPos=0 dst.length=7 dstPos=1 length=7 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at java.lang.System.arraycopy(Native Method) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at java.util.ArrayList.addAll(ArrayList.java:591) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityNodeInfo.init(AccessibilityNodeInfo.java:3248) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityNodeInfo.refresh(AccessibilityNodeInfo.java:903) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityCache$AccessibilityNodeRefresher.refreshNode(AccessibilityCache.java:564) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityCache.refreshCachedNodeLocked(AccessibilityCache.java:206) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityCache.onAccessibilityEvent(AccessibilityCache.java:170) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.view.accessibility.AccessibilityInteractionClient.onAccessibilityEvent(AccessibilityInteractionClient.java:611) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1732) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6938) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 07-03 10:36:10.755 9455 9455 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner 07-03 12:35:21.757 27864 27919 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 27864 07-03 12:35:21.757 27864 27919 E AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected! 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1043) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.app.UiAutomation.disconnect(UiAutomation.java:275) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.app.Instrumentation.finish(Instrumentation.java:248) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:277) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:282) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:271) 07-03 12:35:21.757 27864 27919 E AndroidRuntime: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: FATAL EXCEPTION: main 07-03 13:14:31.468 19100 19100 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 19100 07-03 13:14:31.468 19100 19100 E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: src.length=6 srcPos=0 dst.length=6 dstPos=1 length=6 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at java.lang.System.arraycopy(Native Method) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at java.util.ArrayList.addAll(ArrayList.java:591) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityNodeInfo.init(AccessibilityNodeInfo.java:3248) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityNodeInfo.refresh(AccessibilityNodeInfo.java:903) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityCache$AccessibilityNodeRefresher.refreshNode(AccessibilityCache.java:564) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityCache.refreshCachedNodeLocked(AccessibilityCache.java:206) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityCache.onAccessibilityEvent(AccessibilityCache.java:152) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.view.accessibility.AccessibilityInteractionClient.onAccessibilityEvent(AccessibilityInteractionClient.java:611) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.accessibilityservice.AccessibilityService$IAccessibilityServiceClientWrapper.executeMessage(AccessibilityService.java:1732) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:37) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6938) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 07-03 13:14:31.468 19100 19100 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner 07-03 13:35:56.736 21138 21192 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 21138 07-03 13:35:56.736 21138 21192 E AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected! 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1043) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.app.UiAutomation.disconnect(UiAutomation.java:275) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.app.Instrumentation.finish(Instrumentation.java:248) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:277) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:282) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:271) 07-03 13:35:56.736 21138 21192 E AndroidRuntime: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106)

auto-mator avatar Jul 03 '18 18:07 auto-mator

I have removed tests dependencies but crash shows on my pre-launch report.

Salman-Hameed avatar Mar 04 '19 09:03 Salman-Hameed

Also getting the exact same report, when submitting an app on the Play Store(Fabric reported).

yuejinzhao avatar Mar 15 '19 02:03 yuejinzhao

Same issue on my end for an apk build I am testing:

android.app.UiAutomation.throwIfNotConnectedLocked (UiAutomation.java:676)
android.app.UiAutomation.disconnect (UiAutomation.java:228)
android.app.Instrumentation.finish (Instrumentation.java:198)
androidx.test.runner.MonitoringInstrumentation.finish (MonitoringInstrumentation.java:95)
androidx.test.runner.AndroidJUnitRunner.finish (AndroidJUnitRunner.java:108)
androidx.test.runner.AndroidJUnitRunner.onStart (AndroidJUnitRunner.java:101)
android.app.Instrumentation$InstrumentationThread.run (Instrumentation.java:1741)

I can confirm that while I do have UI tests in place, all of them are being returned out of

if(true){
    return;
}

to test if the issue is actually being caused by my code.

PGMacDesign avatar Mar 18 '19 15:03 PGMacDesign

Same problem on my test project while I ran my UItest without connect my computer. It happend when I let my test sleep for a while and it cannot be restart . At the end it reported java.lang.IllegalStateException: UiAutomation not connected! It there any ideas for this problem? Thanks.

old-eight800 avatar Mar 05 '20 02:03 old-eight800

Same issue here. We are black-box testing android apps on a large scale. This problem appears in roughly 40% of all runs. Is there any work-around for this problem during test execution?

auermich93 avatar Mar 19 '20 14:03 auermich93

The same issue occurs on latest Appium 1.17.1-1 while calling "http://127.0.0.1:8200/wd/hub/session/be4490f0-7be9-48cd-bcae-6a32ed9359c0/screenshot" API Here is the Appium Error Log [35m[WD Proxy][39m Got response with status 500: {"sessionId":"be4490f0-7be9-48cd-bcae-6a32ed9359c0","value":{"error":"unknown error","message":"java.lang.IllegalStateException: UiAutomation not connected!","stacktrace":"java.lang.IllegalStateException: UiAutomation not connected!\n\tat android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1112)\n\tat android.app.UiAutomation.takeScreenshot(UiAutomation.java:709)\n\tat io.appium.uiautomator2.utils.ScreenshotHelper.takeDeviceScreenshot(Unknown Source:169)\n\tat io.appium.uiautomator2.utils.ScreenshotHelper.takeScreenshot(Unknown Source:7)\n\tat io.appium.uiautomator2.utils.ScreenshotHelper.takeScreenshot(Unknown Source:1)\n\tat io.appium.uiautomator2.handler.CaptureScreenshot.safeHandle(Unknown Source:11)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(Unknown Source:0)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(Unknown Source:23)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(Unknown Source:57)\n\tat io.appium.uiautomator2.ht... [debug] [35m[W3C][39m Matched W3C error code 'unknown error' to UnknownError

sriharimobidev avatar Jun 10 '20 09:06 sriharimobidev

Same problem on my test project while I ran my UItest without connect my computer. It happend when I let my test sleep for a while and it cannot be restart . At the end it reported java.lang.IllegalStateException: UiAutomation not connected! It there any ideas for this problem? Thanks.

I am also getting same issue, When I test the android UI interface for a long time and need to sleep for a long time

When I test the android Q UI interface for a long time and need to sleep for a long time, I found that after a long sleep, my test program was killed by the android system, causing Uiautomator to not run normally.

I solved this problem by putting my program in the background process and increasing the priority of the program.

AndroidRuntime: Process: com.example.android.testing.uiautomator.BasicSample, PID: 4216
AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected!
AndroidRuntime: 	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)
AndroidRuntime: 	at android.app.UiAutomation.disconnect(UiAutomation.java:294)
AndroidRuntime: 	at android.app.Instrumentation.finish(Instrumentation.java:249)
AndroidRuntime: 	at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:318)
AndroidRuntime: 	at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:389)
AndroidRuntime: 	at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:378)
AndroidRuntime: 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2196)

EmotionalRonan avatar Aug 01 '20 03:08 EmotionalRonan

I solved this problem by putting my program in the background process and increasing the priority of the program.

Can you let us know the steps you followed to resolve the issue? "I solved this problem by putting my program in the background process and increasing the priority of the program."

ravibabu101143 avatar Dec 06 '22 12:12 ravibabu101143