android / android/android-test

Espresso Tests fail on Android 11

Abierto
#751 15 comentarios 45 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.2k
Forks
342
Merge medio
11 h 29 min
PR fusionados (30 d)
2

Descripción

### 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)

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Empieza reproduciendo las aserciones de launchFragmentInContainer, click y onView en API 30 y compáralas con API 21–29. Después, lee la ruta de fallo de RootViewPicker.java que se muestra en el stack trace e investiga por qué la raíz del diálogo nunca obtiene el foco de ventana. Se considera terminado cuando las aserciones del título y el mensaje del diálogo pasan de forma fiable en API 30 sin introducir regresiones en los otros niveles de API probados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
android, kotlin
Área
mobile, testing
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.