android / android/android-test

Espresso Tests fail on Android 11

Offen
#751 15 Kommentare 45 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
1.2k
Forks
342
Ø Merge
11 Std. 29 Min.
Gemergte PRs (30 T.)
2

Beschreibung

### Description
I have integration tests running from API 21 to API 29. I've been trying to update our app to target API 30 but the tests are flaky just on API 30.

### Steps to Reproduce
1. I have a simple case where I tap on a button that should popup a dialog
```kotlin
btnDialog.setOnClickListener {
MaterialAlertDialogBuilder(this).apply {
setTitle("Test Dialog")
setMessage("This should work on API 30")
setPositiveButton(android.R.string.ok, null)
create()
}.show()
}
```

2. Then I try to test it via:
```kotlin
// Given - fragment is launched
launchFragmentInContainer(...)

// When - the button is clicked
onView(withId(R.id.btn_dialog)).perform(click())

// Then - dialog with message should be shown
onView(withText("Test Dialog")).check(matches(isDisplayed()))
onView(withText("This should work on API 30")).check(matches(isDisplayed()))
```
* I also tried using `RootMatchers.isDialog()` but the same behavior.

### Expected Results
This works perfectly from API 21 to API 29. It should also work in API 30. I also turned off all the compatibility changes just to check and it still is happening.

### Actual Results
Runtime Exception:
```kotlin
java.lang.RuntimeException: 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. Root:
Root{application-window-token=android.view.ViewRootImpl$W@e1847f, window-token=android.view.ViewRootImpl$W@e1847f, has-window-focus=false, layout-params-type=1, layout-params-string={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
fitSides=}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=480, height=854, has-focus=false, 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, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND FIT_INSETS_CONTROLLED
fitSides=}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}}
at androidx.test.espresso.base.RootViewPicker.waitForRootToBeReady(RootViewPicker.java:69)
at androidx.test.espresso.base.RootViewPicker.pickRootView(RootViewPicker.java:37)
at androidx.test.espresso.base.RootViewPicker.get(RootViewPicker.java:16)
at androidx.test.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:9)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.provideRootView(ViewInteractionModule_ProvideRootViewFactory.java:8)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:6)
at androidx.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:7)
at androidx.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:12)
at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:48)
at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:15)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
```

### AndroidX Test and Android OS Versions
AndroidX Test: 1.3.0
Espresso: 3.3.0
Android OS: Android 11 (API 30)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die launchFragmentInContainer-, click- und onView-Assertions auf API 30 zu reproduzieren und sie mit API 21–29 zu vergleichen. Lies dann den im Stacktrace gezeigten Fehlerpfad in RootViewPicker.java und untersuche, warum der Dialog-Root niemals Window-Fokus erhält. Als erledigt gilt die Aufgabe, wenn die Assertions für Dialogtitel und -nachricht auf API 30 zuverlässig bestehen, ohne Regressionen bei den anderen getesteten API-Levels.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, kotlin
Bereich
mobile, testing
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.