# Random failing Android UI test

**URL:** <https://discuss.bitrise.io/t/random-failing-android-ui-test/3813>\
**Category:** Builds\
**Tags:** step\
**Created:** [January 19, 2018, 3:36pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813 "2018-01-19T15:36:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jolanda](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@Jolanda](https://discuss.bitrise.io/u/Jolanda)\
**Post date:** [January 19, 2018, 3:36pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/1 "2018-01-19T15:36:05Z")

</div>

# 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](http://devcenter.bitrise.io/caching/about-caching/#downloading-and-deleting-caches)._ : 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](http://discuss.bitrise.io/t/how-to-debug-your-build-locally-it-works-on-my-mac-pc-but-not-on-bitrise-io/392)? 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](http://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](https://www.bitrise.io/cli) )? If no, can it be reproduced with Docker (using the same docker images / environment we use on [bitrise.io](http://bitrise.io))? Related guide: [Running your build locally in Docker](http://devcenter.bitrise.io/docker/run-your-build-locally-in-docker/) ._

Didn’t try

## Build log

> **[Log in - Bitrise](https://app.bitrise.io/users/sign_in)**
>
> Bringing back the joy of iOS & Android development through automating build, testing and support cycles.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [January 19, 2018, 4:21pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/2 "2018-01-19T16:21:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tamaspapik](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/tamaspapik/32/251_2.png) [@tamaspapik](https://discuss.bitrise.io/u/tamaspapik)\
**Post date:** [January 26, 2018, 11:56am UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/3 "2018-01-26T11:56:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [January 26, 2018, 11:59am UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/4 "2018-01-26T11:59:00Z")

</div>

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](https://blog.bitrise.io/introducing-solid-and-snappy-virtual-device-testing-for-android)

---

<div class="post-metadata">

**Author:** ![b.kopiske](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/b.kopiske/32/2822_2.png) [@b.kopiske](https://discuss.bitrise.io/u/b.kopiske)\
**Post date:** [March 6, 2020, 12:55pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/5 "2020-03-06T12:55:41Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Jeehut](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@Jeehut](https://discuss.bitrise.io/u/Jeehut)\
**Post date:** [April 7, 2020, 1:03pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/6 "2020-04-07T13:03:11Z")

</div>

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

```auto
    - 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. ☹

---

<div class="post-metadata">

**Author:** ![daniel11](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@daniel11](https://discuss.bitrise.io/u/daniel11)\
**Post date:** [January 19, 2021, 11:57am UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/7 "2021-01-19T11:57:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chaitanya.tanna](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@chaitanya.tanna](https://discuss.bitrise.io/u/chaitanya.tanna)\
**Post date:** [January 20, 2021, 9:12pm UTC](https://discuss.bitrise.io/t/random-failing-android-ui-test/3813/8 "2021-01-20T21:12:41Z")

</div>

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

Thanks  
Chaitanya
