Android test fails with a failure to get the focus of root view

android

#1

You run a very simple Android test against an emulator in Circle and the test still fails. If this happens to you, it may be because the emulator screen is locked and test cannot do anything on the screen.

You can unlock the screen by adding the following line before running tests in your circle.yml.

adb shell input keyevent 82

#2

@kimh Thanks this is great, do you have a sample error message for reference?


#3

@levlaz Unfortunately I don’t. I found this when I was working with a customer and couldn’t find nice error messages. I’ve asked the customer to update error message here, so hopefully he will do it.


#4

This is not working for me, unfortunately.
The build can be seen at https://circleci.com/gh/tukak/comicsdbclient/102

The error is :
cz.kutner.comicsdb.MainActivityTest > comicsListandDetail[circleci-android22(AVD) - 5.1] FAILED java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root:
Root{application-window-token=android.view.ViewRootImpl$W@22f0689c, window-token=android.view.ViewRootImpl$W@22f0689c, has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#100 ty=1 fl=#81810100 wanim=0x1030466 surfaceInsets=Rect(0, 0 - 0, 0) needsMenuKey=2}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}

I saw some hint to unlock the screen in application, didn’t try it yet - https://www.reddit.com/r/androiddev/comments/3cegxy/circleci_espresso_continuous_integration/


#5

Could be an emulator without Google APIs. My source: https://riggaroo.co.za/setting-circle-ci-test-deploy-build-android-app/. Worked for me. I’ve downloaded a system image with Google APIs as target.


#6