android / android/android-test

Espresso Tests fail on Android 11

オープン
#751 コメント 15 件 リアクション 45 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
1.2k
フォーク
342
平均マージ
11時間 29分
マージ済み PR(30日)
2

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、API 30 で launchFragmentInContainer、click、onView のアサーションを再現し、API 21–29 と比較します。次に、スタックトレースに示されている RootViewPicker.java の失敗経路を読み、ダイアログのルートがウィンドウフォーカスを取得できない理由を調査します。API 30 でダイアログのタイトルとメッセージのアサーションが安定して通り、他のテスト対象 API レベルでリグレッションが発生しなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, kotlin
領域
mobile, testing
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。