android / android/android-test

Espresso.onView() won't find any view

Open
#645 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

Description
Espresso.onView() doesn't find any view when first showing a dialog, then a second one on top, after finishing the second one.

Steps to Reproduce
Run the test proveEspressoDialogsIssue() here: https://github.com/mobilekosmos/EspressoDialogsIssue/blob/master/app/src/androidTest/java/com/issues/espressoidling/MainActivity2Test.kt

Expected Results
Espresso.onView(withText("OK")).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
should find the view

Actual Results
onView doesn't find anything with a timeout. Removing the second dialog solves the problem, so it seems that something doesn't get updated internally when returning back to the first dialog.
There is a workaround:
Espresso.onView(withText("OK")).inRoot(isDialog()).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
But anyways it should also work without "inRoot(isDialog())"

AndroidX Test and Android OS Versions
All Android versions.
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
androidTestImplementation("androidx.test.espresso:espresso-intents:3.2.0")

Link to a public git repo demonstrating the problem:
https://github.com/mobilekosmos/EspressoDialogsIssue/tree/master/app/src/androidTest/java/com/issues/espressoidling

Contributor guide

Open the contributing guide

Research direction

Run proveEspressoDialogsIssue() from app/src/androidTest/java/com/issues/espressoidling/MainActivity2Test.kt in the linked reproduction project. Compare the failing onView(withText("OK")) lookup with the working inRoot(isDialog()) workaround, then trace the Espresso dialog handling involved. Done means the original lookup finds the first dialog's visible OK view after the second dialog is dismissed.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
mobile, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.