android / android/android-test

DeviceCapture.takeScreenshot() timeout issue

Aperta
#2,273 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
1.2k
Fork
342
Merge medio
11h 29m
PR unite (30g)
2

Descrizione

### Description
Calling `DeviceCapture.takeScreenshot()` in a test rule on test failure times out and takes no screenshot

### Steps to Reproduce
1. Create any kind of Espresso JUnit test
2. Create a test rule extending `TestWatcher()` and try to take a screenshot on failure and write it to test storage.

### Expected Results
Screenshot should be taken and saved in the test storage

### Actual Results
No screenshot is taken, calling `takeScreenshot()` times out.

### AndroidX Test and Android OS Versions
androidx.test.core v1.6.1
androidx.test.espresso:espresso* v3.6.1
OS: Tested on emulators with OS versions 31-33

### Additional debug information
I am just a QA engineer so I can't speak about the app implementation but what I found is that `forceRedrawGlobalWindowViews()` finds 2 views in the context of our app. For one of the views `view.isShown` returns false and the redraw seems to fail on this particular one. I copied the `DeviceCapture` implementation and added a condition to redraw only views that are "shown" and screenshots started working.

**NB** The issue cannot be observed on core v1.5.0 and espresso libraries v3.5.1 but there the `DeviceCapture` implementation is completely different than the latest one.

### Link to a public git repo demonstrating the problem:
Example test rule used
```
class ScreenshotTestRule : TestWatcher() {
override fun failed(e: Throwable?, description: Description?) {
super.failed(e, description)

val className = description?.testClass?.simpleName ?: "NullClassname"
val methodName = description?.methodName ?: "NullMethodName"

takeScreenshot().writeToTestStorage("${className}_${methodName}")
}}
```

Rule added to test class
`@get:Rule(order = 1)
var screenshotWatcher = ScreenshotTestRule()
`

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia leggendo l’implementazione corrente di DeviceCapture.takeScreenshot() e forceRedrawGlobalWindowViews(), quindi confrontala con l’implementazione di core v1.5.0. Riproduci il malfunzionamento con un Espresso TestWatcher e verifica perché una view non mostrata blocca il redraw; il lavoro è concluso quando i test falliti acquisiscono e scrivono uno screenshot sulle versioni 31–33 di Android OS senza andare in timeout.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, kotlin
Ambito
mobile-dev, testing
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.