android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.19k stars 3.61k forks source link

UiAutomator findObject is throwing IllegalStateException: UiAutomation not connected! #89

Open sravanmedarapu opened 8 years ago

sravanmedarapu commented 8 years ago

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.

bootstraponline commented 8 years ago

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

tpetsas commented 8 years ago

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

kevin-brotcke commented 8 years ago

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

tpetsas commented 8 years ago

@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?

kevin-brotcke commented 7 years ago

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

Arvind0203 commented 7 years ago

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.

r-sharma commented 7 years ago

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 commented 7 years ago

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 "); openApp(getConfigProperty()); .... .... Thread.sleep(5000); .... p = InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(cmd);

GauravCreed commented 6 years ago

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)

snijsure commented 6 years ago

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)
manuelrego27 commented 6 years ago

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

martin-price87 commented 6 years ago

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)

jsonpoindexter commented 6 years ago

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)
recodyx commented 6 years ago

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

alejouribesanchez commented 6 years ago

Same issue from my side any ideas how to fix this ?

screen shot 2018-06-06 at 12 54 33 pm
arunsai94 commented 6 years ago

Even i faced the same issue ...!

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

alejouribesanchez commented 6 years ago

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

auto-mator commented 6 years ago

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)

Salman-Hameed commented 5 years ago

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

yuejinzhao commented 5 years ago

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

PGMacDesign commented 5 years ago

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.

old-eight800 commented 4 years ago

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.

auermich93 commented 4 years ago

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?

sriharimobidev commented 4 years ago

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] 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] [W3C] Matched W3C error code 'unknown error' to UnknownError

EmotionalRonan commented 4 years ago

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)
ravibabu101143 commented 1 year ago

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."