Random failing Android UI test

Bitrise Build Issue Report template

Description of the issue

Pretty often when we run a build we get the following exception in our UI tests:
Waited for the root of the view hierarchy to have window focus and not request layout for 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus.

We only have a few basic UI tests at the moment (one textview and imageview, checking if they’re visible) so I don’t expect this to have to do with the tests themselves.

Environment:

Android & Docker, on Ubuntu 16.04

AVD Manager / Wait for Android Emulator / Gradle UI test
Last one fails, but could be because of an issue in one of the other ones.

Reproducibility

  • Does a “Rebuild” help? (You can trigger a rebuild from the Build’s page, by clicking the “Rebuild” button in the top right corner of a finished build) : YES
  • Does a rebuild without caches help? (You can remove the Cache:Pull and Cache:Push steps temporarily to not to use the cache, or you can delete all the caches on the Settings tab of the app. : YES
  • Does the issue happen sporadically, or every time? : Sporadically
  • Does upgrading the build Step to the latest version help? : NO
  • When did the issue start? : Has been going on since we began to use Bitrise (around 2 weeks now)

Local reproduction

Can it be reproduced on your own Mac/PC by following our local debug guide? Please follow at least the first section (“Testing with a full clean git clone”) to make sure to test the state of the code what bitrise.io will get when it does a git clone in the clean environment! If possible please note which sections you tried.

No. Ran the build locally and the UI tests consistently pass.

Local reproduction: Linux / Android (docker based) stack builds

Can it be reproduced by running the build locally, after doing a new git clone of the repository into the /tmp directory and running the build from there with the Bitrise CLI ( Bitrise CLI )? If no, can it be reproduced with Docker (using the same docker images / environment we use on bitrise.io)? Related guide: Redirecting… .

Didn’t try

Build log

1 Like

Thanks for the report @Jolanda, we’ll check it ASAP! :slight_smile:

Hey @Jolanda!

The emulators that are running on Bitrise are in an virtual environment so this causes some performance loss. This means that your tests might run too fast that the emulator can’t always perform properly. Solutions like disabling virtual IME, window animations and so usually helps a lot! Please try disabling them and let’s see if that solves the issue.

1 Like

I’d also suggest you to check the Virtual Device Testing feature, to offload the actual emulator run to specialized environment: https://blog.bitrise.io/introducing-solid-and-snappy-virtual-device-testing-for-android

I’ve got the same issue here. Most of my UI tests fail, although they run perfectly with the Virtual Device Testing feature. I cannot use the Virtual Device Testing feature as I want to collect coverage information for SonarQube integration – and I do not know of any way to get the reports from Firebase Test Labs.

I also tried adding a script step before test execution consisting of

adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0

How can I fix that?

1 Like

Having the same problem here, I’ve tried disabling IME and window animations (but didn’t help):

    - script:
        title: 'ADB: Turn Off Animations'
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -e -x

            adb shell settings put global window_animation_scale 0
            adb shell settings put global transition_animation_scale 0
            adb shell settings put global animator_duration_scale 0
    - script@1.1:
        title: 'ADB: Disable all IMEs'
        inputs:
        - content: |-
            #!/usr/bin/env bash
            set -e -x

            adb shell ime list -a -s | xargs -L1 adb shell ime disable

It’s failing each time I run the tests, and also we just have simple tests in our project. And as @b.kopiske we also can’t use Virtual Device Testing as we need code coverage data collected.

Really sad that this still isn’t solved somehow. :frowning_face:

I also got the same issue here. Sometimes, all of my UI tests failed, though they run perfectly with the Virtual Device Testing feature or in our local machine. The emulator shows ANR dialog. Any idea how to fix this issue?

Hello @daniel11
Can you try to run the build on a different stack and see if it runs successfully?

Thanks
Chaitanya