#2821 added null check

This commit is contained in:
Gouri Panda 2022-05-11 19:44:21 +05:30
parent 4b1c8ae1b0
commit 74e7212067

View File

@ -36,13 +36,21 @@ inline fun <reified T : BaseRobot> T.applyWithViewHierarchyPrinting(
} catch (runtimeException: RuntimeException) { } catch (runtimeException: RuntimeException) {
uiDevice.takeScreenshot(File(context.filesDir, "${System.currentTimeMillis()}.png")) uiDevice.takeScreenshot(File(context.filesDir, "${System.currentTimeMillis()}.png"))
InstrumentationRegistry.getInstrumentation().runOnMainSync { InstrumentationRegistry.getInstrumentation().runOnMainSync {
throw RuntimeException( // During the Pause state, it can't any state or since it may not hold strong reference it
combineMessages( // may garbage collected in the low memory stage or may not return an instance of particular
runtimeException, // activity
ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED).last() val activity =
), ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED).lastOrNull()
runtimeException if (activity != null) {
) throw RuntimeException(
combineMessages(
runtimeException = runtimeException,
activity = activity
),
runtimeException
)
}
throw RuntimeException()
} }
} }
} }