Espresso forces a test to wait 5 seconds on making a screenshot by DefaultFailureHandler when executing method onData()

30 Views Asked by At

I have the following method call that is wrapped into a try-catch block to be able to return true/false:

onData(anything()).inAdapterView(withId(<someId>)).atPosition(<somePosition>).onChildView(withId(<someId>)).check(matches(withText(startWith(<someText>)))).check(matches(isEnabled)))

After updating to Espresso 3.5.1, the operation above takes 5 seconds to execute because Espresso fails on making a screenshot by DefaultFailureHandler:

force redraw failed. Proceeding with screenshot
java.util.concurrent.TimeoutException: Waited 5 seconds (plus 1364169 nanoseconds delay) for androidx.concurrent.futures.ResolvableFuture@db2bc51[status=PENDING, info=[setFuture=[androidx.test.core.app.ListFuture@2210cb6]]]
 at androidx.concurrent.futures.AbstractResolvableFuture.get(AbstractResolvableFuture.java:456)
 at androidx.test.core.app.DeviceCapture.takeScreenshotNoSync(DeviceCapture.kt:120)
 at androidx.test.espresso.base.DefaultFailureHandler.takeScreenshot(DefaultFailureHandler.java:2)
 at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:3)
 at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:5)
 at androidx.test.espresso.ViewInteraction.check(ViewInteraction.java:12)
 at androidx.test.espresso.DataInteraction.check(DataInteraction.java:1)

I don't use DefaultFailureHandler to create screenshots on failures though (looks like it's enabled by default).

This issue causes significant gaps in the method performance due to the 5 sec. delay anytime a I call that method (especially in a loop). It started to happen after Espresso upgrade from 3.1.x to 3.5.1.

I saw the similar issue and the solution there is to disable making screenshots on failures by DefaultFailureHandler. However, as I said above, I don't use it to handle succeeded/failed tests and create screenshots. And the fix is in Espresso 3.6.x-alpha, which I don't want to use in my production code.

This issue also forces the app to show a permission pop-up to provide media access whatever the method is called (I guess for saving a screenshot).

0

There are 0 best solutions below