Espresso's `ViewActions.click()` appears to be flaky
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Inizia eseguendo ripetutamente la riproduzione fornita onView(withText("button test")).perform(click()) su Espresso 3.5.1 e API 34, confrontandola con i livelli API precedenti, se disponibili. Esamina il comportamento del clic in relazione all'interazione mancata segnalata; il lavoro è concluso quando la riproduzione raggiunge in modo affidabile "something new after the button click" oppure quando la limitazione e la causa sono chiaramente documentate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
I recently switched a test suite from API 30 to API 34 devices and I'm witnessing occasional fails (roughly 1 in 5 times across ~300 tests) in tests where we click (via onView(withText("blah")).perform(click())) on something and then expect to see the next screen. Inspecting video recordings for these (I'm using Firebase Testlab), I routinely see that the click has never occurred. I've seen this across multiple parts of a large app, so I'm fairly confident this is a problem in the test code rather than some race condition in the application code.
I had wondered if this was click() being executed before setOnClickListener in some circumstances, but as far as I can tell (through some hacky logging and exception throwing) this isn't the case and Espresso is waiting for the Activity/Fragment lifecycle to complete before interacting (as expected).
My suspicion is that there is some flakiness in click() itself and this seems to be more present in API 34 than it was in earlier versions.
I've tried a couple of different solutions to this that all seem to remove the flakes:
- Using a "try again" mechanism that makes the click, waits for the result it expects, and then tries the click again if it doesn't get it. This is very common in other UI testing frameworks, but not something I've generally had to resort to in Espresso (due to the
IdlingResourcesystem). - Building a custom
OnClickListenerthat can "signal" the tests when the click has actually occurred. Combining this with a "try again" approach allows your code to be certain that the click event has propagated (rather than needing to wait on some change in the view), but is obviously very invasive (we're changing application code to accommodate tests). - Using a custom
ViewActionthat callsperformClick()on theViewinstead of attempting to inject a tap. This feels like a glaringly simple solution, but it doesn't work with all views. For example, aTextViewmight be the child of a clickable view rather than clickable itself (like in the case of a view pager title for instance). My guess is that cases like this were the reason (or at least one of the reasons) for building outViewActions.click()to inject an event in the first place.
Steps to Reproduce
With a view that contains a button that changes screen/alters the view:
onView(withText("button test")).perform(click())
onView(withText("something new after the button click")).matches(isDisplayed())
Expected Results
Espresso will always successfully click on the button.
Actual Results
The click sometimes doesn't happen.
AndroidX Test and Android OS Versions
Espresso 3.5.1 and API 34 running mainly on MediumPhone.arm virtual device on Firebase Test Lab.
- Lingua principale
- Java
- Stelle
- 1.2k
- Fork
- 342
- Merge medio
- 2g 22h
- PR unite (30g)
- 7
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di android/android-test
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
android/android-test#681 · 2 commenti · 1 reazione ·
-
ξεκσνδξδAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 1/100
android/android-test#2499 ·
-
ησξξσAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 1/100
android/android-test#2498 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
android/android-test#2473 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
android/android-test#2461 · 6 commenti · 4 reazioni ·
Tutte le issue di android/android-test
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
aoqia194/leaf-loader#19 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/streampark#4521 ·
-
Update license yearAperta0 - Backlog 1 - Ready documentation good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
cbor
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
FasterXML/jackson-dataformats-binary#844 ·
I maintainer di solito rispondono entro 1 giorno