Closed andresbelt closed 1 year ago
I was getting that error. Then changed the code like below and it worked.
private fun scroll(compilationMode: CompilationMode) {
benchmarkRule.measureRepeated(
packageName = "com.example.macrobenchmark_codelab",
iterations = 5,
metrics = listOf(FrameTimingMetric()),
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
) {
pressHome()
startActivityAndWait()
val contentList = device.findObject(By.res("snack_list"))
val searchCondition = Until.hasObject(By.res("snack_collection"))
// Wait until a snack collection item within the list is rendered
contentList.wait(searchCondition, 5_000)
// Set gesture margin to avoid triggering gesture navigation
contentList.setGestureMargin(device.displayWidth / 5)
// Scroll down the list
contentList.fling(Direction.DOWN)
// Wait for the scroll to finish
device.waitForIdle()
}
}
Thanks! Feel free to open a pull request :)
I think this is actually a bug in the Macrobenchmark library causing this.
Actually, it turned out the bug is WAI. The reason is that you can use StartupMode.COLD
for startup benchmarks, but the process is killed after the setupBlock
, so you can prepare your app (e.g. login), but also start the app cold.
For scrolling benchmark, we generally can't use COLD, because the measure block never won't be cold.
Therefore, the apropriate mode is either startupMode = null
that won't do anything to the app, or StartupMode.WARM
that will restart the activity between each iteration.
I got this error even when without using the startup parameter .. with version upto 1.2.4 ..
It seems like the fix is still in the beta version of 1.3.0. adding the 1.3.0 beta xx version fixes the issue for me.
Bug when ScrollBenchmarks is running
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object androidx.test.uiautomator.UiObject2.wait(androidx.test.uiautomator.SearchCondition, long)' on a null object reference
searchCondition and contentList is null